Hey, I have made a Character Controller that moves around, it works fine but when you go from right to left or forward to backward the transition between directions isn’t smoothed and the transform.forward just changes instantly. I was wondering if anyone knew how to make the transition smooth so the the Player rotates from the current rotation to the next for example right to left. Here is my current Code, if anyone can help that would be nice.
private var moveSpeed : float = 12.0;
private var Drag = 3;
private var ADrag = 3;
private var grounded : boolean;
private var jumpVelocity : float = 8;
private var bottomRight = (Vector3.right + Vector3.back).normalized;
private var bottomLeft = (Vector3.left + Vector3.back).normalized;
private var topRight = (Vector3.right + Vector3.forward).normalized;
private var topLeft = (Vector3.left + Vector3.forward).normalized;
function Update(){
if(grounded){
rigidbody.drag = Drag;
rigidbody.angularDrag = ADrag;
}
if(Input.GetButton("Forwards")){
transform.forward = Vector3.forward;
rigidbody.AddForce(transform.forward * moveSpeed);
}
if(Input.GetButton("Backwards")){
transform.forward = Vector3.back;
rigidbody.AddForce(transform.forward * moveSpeed);
}
if(Input.GetButton("Right")){
transform.forward = Vector3.right;
rigidbody.AddForce(transform.forward * moveSpeed);
}
if(Input.GetButton("Left")){
transform.forward = Vector3.left;
rigidbody.AddForce(transform.forward * moveSpeed);
}
if(Input.GetButton("Forwards") && Input.GetButton("Right")){
transform.forward = topRight;
rigidbody.AddForce(transform.forward * moveSpeed/2);
}
if(Input.GetButton("Forwards") && Input.GetButton("Left")){
transform.forward = topLeft;
rigidbody.AddForce(transform.forward * moveSpeed/2);
}
if(Input.GetButton("Backwards") && Input.GetButton("Right")){
transform.forward = bottomRight;
rigidbody.AddForce(transform.forward * moveSpeed/2);
}
if(Input.GetButton("Backwards") && Input.GetButton("Left")){
transform.forward = bottomLeft;
rigidbody.AddForce(transform.forward * moveSpeed/2);
}
if(!grounded){
rigidbody.drag = 7;
rigidbody.angularDrag = 7;
}
}
function OnCollisionEnter(){
grounded = true;
}
function OnCollisionExit(){
grounded = false;
}
function OnCollisionStay(){
if(Input.GetButtonUp("Jump")){
rigidbody.velocity.y = jumpVelocity;
}
}