Angular Velocity Of RigidBody In The Direction Of Movement | A Unity Tutorial

We can shoot game objects in Unity, but if we don’t give them spin the movement does not look very realistic. To make it look realistic, if the object have rigidbody, we can give it an angular velocity in the direction of the movement and watch it rotating towards its course.

I have created a video tutorial on this on Devsplorer YouTube channel

You can watch it from here or on YouTube

While calculating the angular velocity takes one line of code, as always with development understanding why we are doing what we are could take more time.

Angular velocity vector is not parallel to direction vector but perpendicular to it.
Here in the above image, direction of the white cylinders for the balls points at the position of the game object that is on the target. But their angular velocity vector that we should use so that they will rotate towards to the movement direction, to target is represented with black cylinder.

Objects rotating with world space unit vectors as angular velocity vector

To calculate the direction of the angular velocity vector so that the object rotates towards the movement direction, in the case of the above image towards the target position, we apply cross product to two vectors that connects the selected game object.

The cylinder connected to the sphere on the ground represents the object’s positional vector. The sphere actually is at 0,0,0 position. The other cylinder connected to the selected object is the direction vector that the object will pass through when it starts moving.

When we use these vectors for cross product, we find the direction representing angular velocity and can apply it to our game object.

For details you can check out the video above πŸ‘†

Hopefully, this will be helpful for your projects.
If there was a point not clear please let me know.
See you in the next explorations πŸ™‹


🌟 Sources That Contributed To This Implementation

⭐ HyperPhysics – Rotation Vectors
http://hyperphysics.phy-astr.gsu.edu/hbase/rotv.html#rvec1
⭐ Unity Docs – Cross Product https://docs.unity3d.com/ScriptReference/Vector3.Cross.html
⭐ Wikipedia – Angular Velocity
https://en.wikipedia.org/wiki/Angular_velocity

πŸ‘‰ Wonderful Assets from KayKit – Mini-Game Variety Pack:
https://kaylousberg.itch.io/kay-kit-mini-game-variety-pack
πŸ‘‰ Changing Cursor Texture With Mouse Press:
https://youtu.be/jis0Lq1FLD8
πŸ‘‰ Similar Shooting Series:
https://youtube.com/playlist?list=PLGXzgnKhu_mCTmg_AS66j8U7duSzcsub7
πŸ‘‰ Cylinder Scaling Tutorial
https://youtu.be/s6qhqm3ec28
πŸ‘‰ Previous Video On Target Shooting
https://youtu.be/qA7WbcJmhUM

Leave a comment