- Home /
How can I set the movement of the rigidbodyController in the same direction of the mainCamera view?
I am developing a cardboard app on android and i would like to move the FPScontroller with the xbox pad. I am using the RigidBodyFPSController with the Character Controller component and this script:
public float speed = 6.0F;
//public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
void Update() {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
/*if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;*/
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
The camera rotation works directly in the app and it changes when i move the smartphone and also the Pad movement works but the direction of the movement is different from the view of the camera. Thank you for your answers and sorry if i have done some mistakes with the English.
Edit: I have created this script:
void Update() {
Vector3 eulerRotation = new Vector3(transform.eulerAngles.x, otherObject.transform.eulerAngles.y, transform.eulerAngles.z);
transform.rotation = Quaternion.Euler(eulerRotation);
}
Now the direction of the movement follows the rotation of the camera, but the sensibility of the rotation is too high and with a little move of the head the view starts to rotate very fast. How can i fix this?
Comment