Rotate object to fly like Superman

Ahoy.

I have deadline for sending this to a game development competition tomorrow, so that’s why I need to ask you straight away.

What I’m trying to do is rotate my object to face forward to the direction of movement kind of like Superman does when he’s flying. In my game the player object is steered by giving force from four directions. The player is not supposed to control the rotation of the main character, so no use suggesting that I only apply force to the back of the object.

Here’s an early version of my game: http://koti.kapsi.fi/~leolavi/space/spacejunk.html

You can see that the dude is spinning randomly and not facing forward to the direction of movement. The top of his head should always face forward at the direction he’s headed.

Quick help is hugely appreciated!

Well, first create an empty and put the object inside it. Then align the object’s head with the z-axis of the parent object.

After that, you just need to put the rigidbody on the parent with the script and use this line:

transform.LookAt(transform.position + rigidbody.velocity.normalized);

So simple yet so effective! You just became my favourite person in this forum!

I’m new to Unity and 3D graphics and am not quite grasping how to implement GargerathSunman’s solution. I am using RotateAround to move my object and I need it to point in the direction of travel. This seems like it will work, but I’m having trouble implementing it.

Can someone give me a little more detail about how to do this?

Thanks!