- Home /
Question by
Vioswift · Sep 06, 2015 at 10:01 AM ·
rotationterrainslopeoncontrollercolliderhit
Unity 3D C# - OnControllerColliderHit Position
Hi Im trying to move an object and keep its rotation which the slope of the terrain, for example, when the object goes up a hill, the object rotation changes with it and doesn't stay vertical, this is my code which are failed attempts.
void OnControllerColliderHit(ControllerColliderHit hit) {
//myAng = Vector3.Angle(Vector3.up, hit.normal); //Calc angle between normal and character
//transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal) * transform.rotation;
//transform.Rotate(Vector3.up * Time.deltaTime * 6f);
//transform.rotation = Quaternion.Euler(new Vector3(hit.transform.rotation.x, transform.rotation.y, hit.transform.rotation.z));
transform.rotation = Quaternion.LookRotation(new Vector3(hit.transform.position.x, transform.rotation.y, hit.transform.position.z));
}
Comment
Little confused - do you expect A) the object to stay perfectly vertical and not change rotation/tilt or B) mimic the slope of the terrain?
Your answer
Follow this Question
Related Questions
Unity automatically rotate camera on slopes up/down 0 Answers
Making a particle effect parallel to the slope of a terrain 1 Answer
Make an instantiated object match the slope of the terrain 1 Answer
Bound the gameobject from the ground 1 Answer
Climbing script - impossible get under the map and turning around 0 Answers