- Home /
Question by
smithdam1 · May 17, 2018 at 05:37 AM ·
controllerplayer movementmovepositionrigibody
make Rigidbody MovePosition use characters rotation,Moving rigidbody with MovePosition on its forward, right
I have this code
{
float inputX = Input.GetAxis("RightStickHorizontal");
float x = Input.GetAxis("Horizontal") * Time.deltaTime * movementSpeed;
float z = Input.GetAxis("Vertical")* Time.deltaTime * movementSpeed;
Vector3 movement = new Vector3(x, 0.0f, z);
MouseX = Input.GetAxis("Mouse X");
FinalInputX = inputX + MouseX;
rotX += FinalInputX * InputSensitivity * Time.deltaTime;
rb.MovePosition(transform.position + movement);
Quaternion LocalRotation = Quaternion.Euler(0, rotX, 0);
rb.MoveRotation(LocalRotation);
}
It works for moving and rotating but the character moves along the world axis and not it's local. W moves along world Z no matter where Im facing etc. What do I need to get it moving based on where it's looking?
Comment
Best Answer
Answer by smithdam1 · May 17, 2018 at 06:47 AM
Found it. Needed to add: movement = transform.TransformDirection(movement); to localize it.
Your answer
Follow this Question
Related Questions
Stop walking while in air with Animator.setFloat() 1 Answer
How do I disable player input action map and enable the UI action map? 4 Answers
Rigidbody Controller move forward in the direction of the camera 0 Answers
Save my WEEK: Converting root motion controller script into jetpack controller script 0 Answers
Player Movement 0 Answers