my current setup has 4 relevant variables, vx, vy, speed, and heading. I want to take in the heading as an angle in radians, and set vx and vy to values that would have the hypotenuse of the triangle to be equal to speed. I'm guessing you would use `tan()`

for this, but I'm not familiar with how the `sin() cos() tan()`

functions work in lua, or any other language for that matter

(untested) I believe it's as simple as

```
vx = speed * math.cos(heading)
vy = speed * math.sin(heading)
```

I'm looking for the reverse of this as well, I technically have vx and vy values in the form of the difference between the enemy and the enemy target, but I don't have a way of preserving that direction while setting the speed to the desired value. I should have been clearer in the original post, thanks!

Let me direct you to this useful pdf

1 Like

thanks, that worked!