Creating a vertical limiter (with range)

Hello - We have spent a great deal of time trying to figure out how to solve this problem to no avail. We are trying to limit our character’s ability to climb terrain or “jump” off of objects once it collides with them.

Basically we want to give some flexibility in y-axis and not limit it completely (let’s say +/- 5.

We have tried:

  1. Adding a giant invisible box/ plane collider above the level. Problem is our RPG style controls seem to get really messed up/ distorted trying to click through it.

  2. Trying using a formula involving mathf.clamp which we think is right but cant get it to restrict the characters y-movement after a collision or if it tries to climb terrain.

  3. Tried to add a small invisible box that follows the character but can’t get it to react fast enough.

Hopefully this is simple solution. I am open to trying any other options you may have. Thanks a lot for the help. Happy coding!

function FixedUpdate() {


if(moving) {
 //Calculate percentage of movement towards movePos
 var movementPercentage = (Time.time - moveStartTime) / moveTime;
 if(movementPercentage > 1) { //We've reached the goal
 rb.MovePosition(goalPos);
 moving = false;
 } 

else { //Still going
 //Calculate new position
 var pos : Vector3;
 {
 pos.x = Mathf.SmoothStep(moveStartPos.x, goalPos.x, movementPercentage); //Ease x movement
 pos.y = rb.position.y; //y position doesn't change
 pos.z = Mathf.SmoothStep(moveStartPos.z, goalPos.z, movementPercentage); //Ease y movement
 rb.MovePosition(pos); //Set position
 }
 }
 }
}

I like this solution:

http://answers.unity3d.com/questions/63320/how-can-i-stop-my-player-from-being-able-to-jump-u.html

should point you in the right direction