Rotation noob help please!!!
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)
).normalized;
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?
Thanks.
Your answer
Follow this Question
Related Questions
Rotating an Object (To Face Another Object) Only on X and Y Axis 3 Answers
My rotation is not the same in inspector as it is in the scirpt 0 Answers
Cant stop object/ridgidbody from rotating 2 Answers
Rotation is broken 2 Answers
Need help aiming at new world space co-ordinates for gun recoil/spray pattern 0 Answers