- Home /
Question by
Pure_hate · Jun 19, 2015 at 06:26 PM ·
camerafirst person controllermoving platform
Problem with 1st person camera rotation after jumping on a platform
I have 1st person rigidbody player controller from standart unity assets. I made moving and rotating platform as a kinematic rigidbody with simple script.
// Actual platform movement
void Update() {
transform.Translate(moveSpeed * Time.deltaTime, space);
}
// Platform rotation
void FixedUpdate () {
Quaternion deltaRotation = Quaternion.Euler(rotationSpeed * Time.deltaTime);
rb.MoveRotation(rb.rotation * deltaRotation);
}
Also to let player stand on a platform I made him a child of platform after jumping on it. The problem is that after jumping on the platform players camera rotates (because of the existing platform rotation). To fix that I tried to add into player controller script:
void OnCollisionEnter (Collision hit) {
if (hit.gameObject.tag == "Platform") {
Debug.Log (transform.rotation.eulerAngles + "\n");
transform.Rotate(hit.transform.rotation.eulerAngles*(-1));
Debug.Log (transform.rotation.eulerAngles + "\n");
transform.parent = hit.transform;
Debug.Log (transform.rotation.eulerAngles + "\n");
}
}
But this didn't solve the problem. Log shows that rotation was succesfull, but in fact camera rotates the same as it was before.
Comment