# Python Slope Limit

I finally got into python, and it is beautiful. But, I was wondering how you limit the slope an object can walk up.

Thanks

### Attachments

Scripting movement.blend (441 KB)

The easiest way is to just allow your player to walk on specific ground (ground with a certain property). Make steep slopes separate objects from the regular ground but don’t include the property to allow the player to walk on them.

The other way involves a little bit of math (math that is currently out of my league). It requires looking at the ground normals to check the steepness of a slope and whether the player can walk on them or not. Hopefully someone can better explain this and maybe provide an example.

But maybe you’re looking for a simple way so the first idea is the best

I had no idea it wasn’t easy. :’( I was thinking of doing an environment that is slowly rotating (Star Wars Jedi Knight Dark Forces 2; Falling Ship). I could try a small box that has the ground-detecting sensor so if it is too steep, you can’t go up it at all. Hmmm. . .

Oh, well, it’s not like super complex. I’m sure one of the better coders can help you out.

How would I get a sensor from another object?

I was hoping onGround = cont.sensors[“onground”] (where onground is the sensor from another object)

would work.

Edit: My bad, cont gets the object holding the controller.

If you don’t want to just use object properties, here’s a more dynamic method you can use.

Cast a ray directly down from your character using the rayCast method. The third returned value is the hit face’s normal vector. Get the angle between this vector and the vertical vector (0, 0, 1) using the Vector.angle method. If the angle is greater than some threshold, don’t let the character walk on that surface.

Ha. I wasn’t aware of the existing method. This is awesome This helped me too.

Cast a ray forwards for two or three units and it it hits something, then the slope is steep!

if you use force , then if the force to go forward is < 9.8 and there a slope of 45° you cannot walk on it (unless that you have already some velocity):

vel = own.localLinearVelocity
if keyW and vel.y < 5 : own.applyForce((0,9.0,0),1)

the velocity instead, by-bass the gravity in someway.