I'm trying to rotate my characterController player on a slope on the 'x' and 'z' axises, however things aren't going so well.
The player does rotate, but if I move and look in another direction, the characterController will still be on the same axis, and won't look down an up slope, and instead will be looking up a down slope.
void Update ()
{
Vector3 rotateDirection = (camera.forward * Input.GetAxis("Vertical"))
+ (camera.right * Input.GetAxis("Horizontal"));
Quaternion newRotation = Quaternion.LookRotation(
new Vector3(rotateDirection.x, 0f, rotateDirection.z));
transform.rotation = Quaternion.Slerp(
transform.rotation, newRotation, rotSpeed * Time.deltaTime);
}
private void OnControllerColliderHit(ControllerColliderHit hit)
{
transform.rotation = Quaternion.Euler(hit.transform.rotation.eulerAngles.x,
transform.rotation.eulerAngles.y, hit.transform.rotation.eulerAngles.z);
}
Also, it doesn't work at all with spheres and terrain since their rotation is zero. Anyone know how to achieve what I am talking about? Also, the goal is to allow for the 'y' axis to be free and do what it needs to in void Update()
.