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

Ece Sefercioğlu
3 min readJan 9, 2021

--

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 has 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 the direction vector but perpendicular to it.
Here in the above image, the 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 the movement direction, the target is represented with the black cylinders.

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 connect 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

Originally published at http://devsplorer.wordpress.com on January 9, 2021.

--

--

Ece Sefercioğlu

Indie Game Developer/Blogger/Student likes to tweak around the mechanics and share