- Home /
When I move and then rotate my direction doesn't change.
When I rotate I keep moving the same direction. Can someone help?
using UnityEngine;
using System.Collections;
public class PlayerScript : MonoBehaviour {
public float moveSpeed = 10;
public float sprintSpeed = 15;
public float jumpSpeed = 20;
public float gravity = 10;
CharacterController controller;
Vector3 currentMovement;
void Start () {
controller = GetComponent<CharacterController> ();
}
void Update () {
currentMovement = new Vector3 (Input.GetAxis ("Horizontal") * moveSpeed, currentMovement.y, currentMovement.z);
currentMovement = new Vector3 (currentMovement.x, currentMovement.y, Input.GetAxis ("Vertical") * moveSpeed);
if (Input.GetButtonDown ("Jump") && controller.isGrounded)
currentMovement = new Vector3 (currentMovement.x, jumpSpeed, currentMovement.z);
controller.Move (currentMovement * Time.deltaTime);
if (!controller.isGrounded)
currentMovement -= new Vector3 (0, gravity, 0);
if (Input.GetMouseButton(1))
transform.Rotate (0, Input.GetAxis("Mouse X") * Time.deltaTime, 0);
currentMovement = transform.rotation * currentMovement;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612001542im_/https://answers.unity.com/themes/thub/images/avi.jpg)