- Home /
Trouble with correct move and rotation of Rigibody
Hi, I have trouble with correct move and rotation of Rigibody, please help. So, I have:
Rigibody object (player)
My move script use:
AddRelativeForce(speed*Input.GetAxis("Horizontal",speed*Input.GetAxis("Vertical"), 0.0f)
as I need move it in local coordinatesI rotate player's "face" in direction of move with:
transform.forward = velocity
There's UI Canvas joystick for move
The Main camera has target (player) and rotate with him (behind his back), but it's not child of player.
I have one problem - when I press any down direction key on the joystick , and player turn back at angle >90 deg (specially - 180 deg) and starts move, he also starts crazy rotate dance. I haven't this, if I comment //transform.forward = velocity
But then I can't rotate player face to move vector.
If I use .AddForce
instead .AddRelativeForce
- I also haven't this problem, but have other - the force will in global coordinates, not in local and as my camera rotate with player, I have mirror effect for joystick with rotate >90 deg (when I press left it is right and vice versa- local view but global controlling). So I need use .AddRelativeForce
.
The problem with player rotation, as I guess, I have conflict of .AddRelativeForce
for move (in local coordinates) and transform.forward = velocity
for rotate player's face (in global coordinates). I found in forums, that I must use Vector3.forward instead transform.forward, but how can I use it? just Vector3.forward=velocity
? So please, help with right code for face orientation of player, if player is Rigidbody and it has local coordinate for move ( .AddRelativeForce
. ). Thanks for help
Your answer
Follow this Question
Related Questions
Help with Grid Movement 2 Answers
Rotating Player 0 Answers
use world axis when using transform.rotate 3 Answers
use world axis when using transform.rotate 0 Answers
movement doesnt stop when jump pad is tapped at the same time 0 Answers