Can only go horizontally while walking on walls, and not vertically
Hello!
I'm trying to modify the RigidbodyFPSWalker to make it able to walk on walls, however it's not really working as it should.
Here's the script:
if (grounded)
{
// Calculate how fast we should be moving
targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
targetVelocity = transform.TransformDirection(targetVelocity);
targetVelocity *= speed;
// Apply a force that attempts to reach our target velocity
velocity = rb.velocity;
Vector3 velocityChange = (targetVelocity - velocity);
velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
velocityChange.y = 0;
rb.AddForce(velocityChange, ForceMode.VelocityChange);
}
I'm using a Constant Force to modify the gravity. When the rigidbody is on a wall, I can only go Horizontally, and not vertically.
Comment