Skip to content Skip to sidebar Skip to footer

How To Move Character Forward And Also Face Moving Direction?

I am a newbie to Unity, any help will be much appreciated. I want to make a game where character (shown in below image) moves forward continuously. Character has to move upwards wh

Solution 1:

You can take a look into one of the Quaternion functions - LookRotation:

https://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html

The code should be as simple as this:

Vector3relativePos= target.position - transform.position;
Quaternionrotation= Quaternion.LookRotation(relativePos);
transform.rotation = rotation;

where target.position is the position where you touch the screen, transform.position is the position and transform.rotationis the rotation of your moving object.

Hope this helps :)

Post a Comment for "How To Move Character Forward And Also Face Moving Direction?"