void upgrade () ControllPlayer(); void ControllPlayer() rise moveHorizontal = Input.GetAxisRaw ("Horizontal"); rise moveVertical = Input.GetAxisRaw ("Vertical"); Vector3 activity = new Vector3(moveHorizontal, 0.0f, moveVertical); transform.rotation = Quaternion.LookRotation(movement); transform.Translate (movement * movementSpeed * Time.deltaTime, Space.World); if(Input.GetButtonDown ("Fire1")) animation.Play ("attack-01"); Now the just thing that"s wrong through it is, that when I stop pressing the movement tricks on the gamepad, the Player turns immediately in the forward direction.I would favor him to remain as that was when moving. Is there a rapid fix to this?




You are watching: Unity rotate player in direction of movement

*
robertbu · Oct 05, 2014 at 02:03 afternoon 0

This line here:

transform.rotation = Quaternion.LookRotation(_movement.normalized);Is a quite standard method of getting things to challenge the relocate direction (don"t require ".normalized"). Just how is that failing? If the rotation of her character is (0,0,0), is the front side facing positive "z"?


*
KayelGee · Oct 06, 2014 in ~ 12:05 pm 0
*
bubzy · Oct 10, 2014 in ~ 09:07 am 2

how about

if(moveHorizontal != 0 && moveVertical != 0) transform.rotation = Quaternion.LookRotation(movement);

*
ggMikael bubzy · january 30, 2017 at 11:19 pm 0
*
PaxForce · Oct 10, 2014 in ~ 10:30 am 1

thanks for the idea - ns can"t believe how basic this to be to settle :)...althought...you acquired one point wrong. The correct way is this:

if(moveHorizontal != 0 || moveVertical != 0) transform.rotation = Quaternion.LookRotation(movement);

the difficulty was that ns was relocating in Space.Self instead of Space.World.fixed and also done.

rise moveHorizontal = Input.GetAxisRaw ("Horizontal"); to rise moveVertical = Input.GetAxisRaw ("Vertical"); Vector3 activity = brand-new Vector3(moveHorizontal, 0.0f, moveVertical); transform.rotation = Quaternion.LookRotation(movement); transform.Translate (movement * movementSpeed * Time.deltaTime, Space.World);
How did you finish up specifically fixing this? I"m still stuck to this problem and also the password you posted here is the same as the one in her Question. Ns don"t obtain how to set my player to move in space,world ins$$anonymous$$d of space.self


THAN$$anonymous$$S A LOT!!! the works prefer a charm :) yet you can use the slerp come smooth the out.




See more: Guitar Hero Live Supreme Party Edition Song List Of Songs In Guitar Hero Live

Thanks dude! i had actually no idea you can use .LookRotation();, yet now ns do. This really helped me progression as a developer, i"m new.


Sorry because that the necropost, yet I am sure a lot of of human being are more than likely stumbling across this question. I myself a few hours earlier found this concern while in search of "How to do the player face movement direction" now I i found it this question is currently solved, and also the answer functions great. After ~ doing a little bit of study on Slerp, i made that so the script (that PaxForce made) will certainly smoothly turn rather of act a sharp turn when rotating.

The method it to be done was by instead of transform.rotation = Quaternion.LookRotation(movement); v transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement), 0.15F);

If anyone wanted to know how it works, Quaternion.Slerp bring away 3 arguments: 2 Quaternions and also 1 Float. The interpolates the rotation in between the 2 Quaternions v a rate of the Float worth (0.0 is no activity while 1.0 is prompt Movement.) The password I go interpolates the rotation between the existing Rotation (transform.rotation) and the movement Rotation (Quaternion.LookRotation) through a rate of 0.15F.