I wona to move a cube with rotate,So that the move is due to the rotation.
like this image:
my code is :
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
// Use this for initialization
void Start () {
}
void Update() {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
float mv = Input.GetAxis("Horizontal");
transform.Rotate(Vector3.forward,-mv);
moveDirection = new Vector3(mv* Time.deltaTime, mv* Time.deltaTime, 0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
how I can do it?
when when player has been rotate the Axis is not work move to forward.