Angle From Velocity

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
22alpha22
Posts: 308
Joined: Fri Feb 21, 2014 5:04 pm
Graphics Processor: nVidia with Vulkan support
Location: Montana, USA

Angle From Velocity

Post by 22alpha22 »

VelFromAngle and Vel3DFromAngle are incredibly useful functions for those of us who lack trigonometry skills, however I have noticed there doesn't seem to be a function or functions to retrieve the relative angle and/or pitch an object is traveling toward based on its velocity. This function would be basically the inverse of the two functions already mentioned. I need such a function so that I can adjust an object's relative forward velocity to include its pitch all without changing the direction the object is facing.

I may not have explained that very well. Basically what I want to do is spawn an object and be able to set its velocity relative to the direction it is facing. So XVel would be forward/backward, YVel would be side to side, and ZVel would be up/down. I have no problem setting that up, the issue is, I want to be able to pass a flag to the function that will also include the object's pitch in its forward velocity calculations. I thought I could just use Vel3DFromAngle until I realized that the object might not necessarily be traveling toward the direction it is facing, so I need a way to pass on an angle to Vel3DFromAngle that is based on the object's current velocity independent of the angle it is actually facing. It would also be helpful to be able to get a pitch value based on an object's velocity as well, but that is not as important right now.
Jarewill
 
 
Posts: 1853
Joined: Sun Jul 21, 2019 8:54 am

Re: Angle From Velocity

Post by Jarewill »

Would A_FaceMovementDirection do what you want to do?
User avatar
22alpha22
Posts: 308
Joined: Fri Feb 21, 2014 5:04 pm
Graphics Processor: nVidia with Vulkan support
Location: Montana, USA

Re: Angle From Velocity

Post by 22alpha22 »

Thanks for the quick response. I never even thought about that function and it may be a rather genius workaround. Of course I will have to save the object's angle and pitch before using that function so that I can reset them after using it but that shouldn't be a problem. I will try this out and see how it goes.
User avatar
KeksDose
 
 
Posts: 596
Joined: Thu Jul 05, 2007 6:13 pm
Location: my laboratory
Contact:

Re: Angle From Velocity

Post by KeksDose »

You can recover the horizontal angle with VectorAngle(vel.x, vel.y) and pitch with VectorAngle(vel.xy.length(), vel.z).
User avatar
22alpha22
Posts: 308
Joined: Fri Feb 21, 2014 5:04 pm
Graphics Processor: nVidia with Vulkan support
Location: Montana, USA

Re: Angle From Velocity

Post by 22alpha22 »

Thank you so much, that is exactly what I was looking for, much appreciated.
Post Reply

Return to “Scripting”