- Home /
Rotate a GameObject in the Vector3 direction?
I am making a mobile game and everything is working but the character rotation. I got the movement code which uses the Unity Standard Assets joystick to move the character around.
         vertical = CrossPlatformInputManager.GetAxisRaw ("Vertical");
         horizontal = CrossPlatformInputManager.GetAxisRaw ("Horizontal");
 
         Vector3 playermovement  = new Vector3 (horizontal,player.position.y*0f, vertical);
         playerbody.AddForce (playermovement*speed);
This works great and the player is moving in the exact position I go with the mobile joystick but I want the player to also rotate in the direction it's going on the Y axis. For example to rotate right and left etc.. I tried messing around with quaternions but I cannot get it to work..
Answer by toddisarockstar · Mar 06, 2017 at 04:14 AM
             void Update () {
     transform.rotation = Quaternion.LookRotation (Vector3.RotateTowards (transform.forward, playermovement, 5 *Time.deltaTime, 0.0F));
 }
     
 
Your answer
 
 
             Follow this Question
Related Questions
why is my character rotation always 180° after joystick is released. 1 Answer
Transform a Vector by a Quaternion 1 Answer
How would I smooth out a Quaternion? 2 Answers
Random.insideUnitCircle seems to reproduce similar vectors 1 Answer
Rotation of object placed in the middle point between two points? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                