Hello I am rotating my player using:
if (IsInLocomotion() && ((y >= 0 && z >= 0) || (y >= 0 && z < 0) || (y < 0 && z >= 0) || (y < 0 && z < 0)))
Vector3 rotationAmount = Vector3.Lerp(Vector3.zero, new Vector3(0f, rotationDegreePerSecond
* (z < 0f ? -1f : 1f), 0f), Mathf.Abs(z));
Quaternion deltaRotation = Quaternion.Euler(rotationAmount * Time.fixedDeltaTime);
this.transform.rotation = (this.transform.rotation * deltaRotation);
But I also want to keep him facing the gorund so I tried adding:
Physics.Raycast(backLeft.position + Vector3.up, Vector3.down, out lr); Physics.Raycast(backRight.position + Vector3.up, Vector3.down, out rr); Physics.Raycast(frontLeft.position + Vector3.up, Vector3.down, out lf); Physics.Raycast(frontRight.position + Vector3.up, Vector3.down, out rf);
upDir = (Vector3.Cross(rr.point - Vector3.up, lr.point - Vector3.up) +
Vector3.Cross(lr.point - Vector3.up, lf.point - Vector3.up) +
Vector3.Cross(lf.point - Vector3.up, rf.point - Vector3.up) +
Vector3.Cross(rf.point - Vector3.up, rr.point - Vector3.up)
this.transform.up = upDir;
This works pretty well facing him to the ground but it cancels my other rotation. How could I go about keeping my initial rotation but also adding a element to face the player to the ground?
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
117 People are following this question.
Rotation and Gravity Relative to the Center of an Object
Rotating an object between two positions??
transform.rotation spazes out
After gameObject rotation is set, it changes to a different value
i have a spin wheel and a button when i click the button i need to rotate the wheel for a certain period,each time the rotation speed should be random