So I was trying to make a character move and now when I go to turn while walking I start sliding in a circle… how do I fix that so I can make the character turn with the slide kinda like a call of duty walk?
#pragma strict
var playerAcceleration : float = 500;
var cameraObject : GameObject;
var maxSpeed : float = 20;
var horizontalMovement : Vector2;
var deacceleration : float;
var deaccelerationX : float;
var deaccelerationZ : float;
var jumpSpeed : float = 500;
var maxSlope : float = 60;
var grounded : boolean = false;
function Update ()
{
horizontalMovement = Vector2(GetComponent.().velocity.x,GetComponent.().velocity.z);
if (horizontalMovement.magnitude > maxSpeed)
{
horizontalMovement = horizontalMovement.normalized;
horizontalMovement *= maxSpeed;
}
GetComponent.().velocity.x = horizontalMovement.x;
GetComponent.().velocity.z = horizontalMovement.y;
if(Input.GetAxis(“Horizontal”) == 0 && Input.GetAxis(“Vertical”) == 0)
{
GetComponent.().velocity.x = Mathf.SmoothDamp(GetComponent.().velocity.x,0,deaccelerationX, deacceleration);
GetComponent.().velocity.z = Mathf.SmoothDamp(GetComponent.().velocity.z,0,deaccelerationZ, deacceleration);
}
transform.rotation = Quaternion.Euler(0,cameraObject.GetComponent(MouseLook).CurrentYRotation,0);
GetComponent.().AddRelativeForce(Input.GetAxis(“Horizontal”)*playerAcceleration * Time.deltaTime,0,Input.GetAxis(“Vertical”)*playerAcceleration * Time.deltaTime);
if (Input.GetButtonDown(“Jump”)&& grounded)
{
GetComponent.().AddForce(0,jumpSpeed,0);
}
}
function OnCollisionStay(collision: Collision){
for(var contact : ContactPoint in collision.contacts){
if(Vector3.Angle(contact.normal,Vector3.up) < maxSlope){
grounded = true;
}
}
}
function OnCollisionExit(){
grounded = false;
}