# custom rigidbody movement problem

hi, im using a custom rigidbody movement script, and it works fine, it moves well and interacts with physics perfectly, but one problem, i can climb up walls witch i dont want, how do i fix that? this is the script, it in javascript:

`````` var forwardSpeed = 10;

var backwardSpeed = 5;

var strafeSpeed = 8;

function FixedUpdate () {

// Step1: Get your input values

horizontal = Input.GetAxis("Horizontal");

vertical = Input.GetAxis("Vertical");

// Step 2: Limit the movement on angles and then multiply those results

// by their appropriate speed variables

percentofpercent = Mathf.Abs(horizontal) + Mathf.Abs(vertical) - 1.0;

if (percentofpercent > 0.1) {

// if we're here, then we're not moving in a straight line

// my math here might be kinda confusing and sloppy...so don't look!

percentofpercent = percentofpercent * 10000;

percentofpercent = Mathf.Sqrt(percentofpercent);

percentofpercent = percentofpercent / 100;

finalMultiplier = percentofpercent * .25;

horizontal = horizontal - (horizontal * finalMultiplier);

vertical = vertical - (vertical * finalMultiplier);

}

if (vertical > 0) {

vertical = vertical * forwardSpeed;

}

if (vertical < 0) {

vertical = vertical * backwardSpeed;

}

horizontal = horizontal * strafeSpeed;

// Step 3: Derive a vector on which to travel, based on the combined

// influence of BOTH axes

tubeFinalVector = transform.TransformDirection (Vector3(horizontal,0,vertical));

// Step 4: Apply the final movement in world space

rigidbody.velocity.z = tubeFinalVector.z;

rigidbody.velocity.x = tubeFinalVector.x;

}

function Awake () {

rigidbody.freezeRotation = true;

}
``````

A good working example of this climbing limitation you describe can be found in the default assets of Unity3d, in the basic character controller there is a so called slopeLimit parameter this is based on steepness angle. So you can have the script decide what angle your rigidbody can ascend prehaps in the case of a wall accept every slope under 90 degrees.

declarations:

``````var ticktock:boolean;
var prevPos;
var pmd;
``````

place in update

``````if (!ticktock)
{
prevPos = Vector2(transform.position.x,transform.position.z);
ticktock = true;
}
else
{
pmd = Vector2.Angle(prevPos,vector2(transform.position.x,transform.position.z));
ticktock = false;
}
if (pmd != null && Raycast (transform.position, Vector3(pmd.x,,pmd., 115, 0))
{
rigidbody.velocity.z = 0;

rigidbody.velocity.x = 0;
}
``````