Hi,
I made a controller based on this code
http://wiki.unity3d.com/index.php?title=RigidbodyFPSWalker
But when I jump into the wall, the character gets stuck while I press foward and makes things don’t work very well.
I already searchd a solution and tryed to apply it. Basically, was to avoid the movement using rigidbody.SweepTest.
But it isn’t working very well. Is there a way to suddenly stop the object speed instead of letting it slowly stop?(that causes to get stuck)
function FixedUpdate () {
// Calculate how fast we should be moving
var targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
var hit:RaycastHit;
//Calculate if it's going to collide
if(rigidbody.SweepTest(targetVelocity, hit, dist)){
//Pretend that no keys were pressed
targetVelocity. x = 0;
}
targetVelocity = transform.TransformDirection(targetVelocity);
targetVelocity *= speed;
// Apply a force that attempts to reach our target velocity
var velocity = rigidbody.velocity;
var velocityChange = (targetVelocity - velocity);
velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
velocityChange.y = 0;
rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
rigidbody.AddForce(Vector3 (0, -gravity * rigidbody.mass, 0));
}