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.
Angle From Velocity
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!)
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!)
Re: Angle From Velocity
Would A_FaceMovementDirection do what you want to do?
- 22alpha22
- Posts: 308
- Joined: Fri Feb 21, 2014 5:04 pm
- Graphics Processor: nVidia with Vulkan support
- Location: Montana, USA
Re: Angle From Velocity
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.
Re: Angle From Velocity
You can recover the horizontal angle with VectorAngle(vel.x, vel.y) and pitch with VectorAngle(vel.xy.length(), vel.z).
- 22alpha22
- Posts: 308
- Joined: Fri Feb 21, 2014 5:04 pm
- Graphics Processor: nVidia with Vulkan support
- Location: Montana, USA
Re: Angle From Velocity
Thank you so much, that is exactly what I was looking for, much appreciated.