- Home /
Unity Third Person Character Controller(Standard Assets ver) Orient to Normal and keep its rotation from movement?
Hello. I'm using the standard assets Third Person Controller that comes with Unity for my group's game and we are trying to get a rotation towards the normal. In the update function, I have the following for what I thought is the correct approach to rotation. I'll fix the smooth interpolating later as this is testing code. I've been looking at the following link for help. http://answers.unity3d.com/questions/168097/orient-vehicle-to-ground-normal.html
if(IsGrounded()) {
var turn : float = Input.GetAxis("Horizontal") * rotateSpeed * Time.deltaTime;
curDur = (curDir + turn) % 360;
if (Physics.Raycast(transform.position, -curNormal, Rayhit))
{
curNormal = Vector3.Lerp(curNormal, Rayhit.normal, * Time.deltaTime);
var grndTilt : Quaternion = Quaternion.FromToRotation(Vector3.up, curNormal);
transform.rotation = grndTilt * Quaternion.Euler(0, curDir, 0);
}
}
Now, I'm still looking at the controller and its movement calculation. Still, when this code is inserted in the update(), the object DOES rotate to the normal, albeit clunky, but the rotation based on its turning or its current forward direction doesn't apply anymore.
My guess is in Quaternion.Euler. I'm still confused as to how this works aside from its relation to rotating the object. The arguments of 0 may have something to do with it. Please help me. Note that I did not change anything involving the character controller's movement aside from its variables.
Would multiple calls to transform.rotate in the same update function cause trouble? There is a call if the player is grounded for the player to call transform.rotate on itself to face its moveDirection using Quaterion.LookRotation
Again, little to nothing has been changed with this default controller. So one can look at the default controller and give me advice.
Also, our player is a model from the NASA 3D models page, so no animations are necessary; just a simple mesh renderer was used. The player does rotate and move without this code, but once I included it, the orientation happens, but the rotate towards the player's forward no longer works.