I’ve been setting my levels up for my game and noticed that i’ve had to add a heck of a lot of bounding boxes to stop people from being able to bunny hop up slops and walls.
Most of the objects don’t really fit in with a bounding volume either and the best fit often leave areas cut off where you should be able to walk.
What i was think was to have the walls and inclimbable slopes tagged with not walkable or not grounded so that the character controller will not walk up them or allow you to bunny hop up them.
The way I do it is to slide characters off of slopes that’re too slope-y for them.
When they hit a slope that’s a certain angle off the ground, sliding is set to non-zero and a different movement is calculated instead of accepting player input.
private var sliding : Vector3 = Vector3.zero;
function Update() {
// ... Do stuff
// ... and things
// ... then when you're ready to move the character -
if ( onGround sliding != Vector3.zero ) {
var slideMovement = Vector3(sliding.x, -sliding.y, sliding.z);
Vector3.OrthoNormalize (sliding, slideMovement);
collisionFlags = controller.Move( (slideMovement*slideSpeed+Vector3(0,-8,0) ) * Time.deltaTime );
slideSpeed += -slideMovement.y * Time.deltaTime * 9.81;
} else {
// do normal, non-sliding movement (i.e., use player input)
}
// ... finish Update
}
var minSlideSlope : float; // how many degrees up from flat it takes before a char starts sliding
function OnControllerColliderHit ( hit : ControllerColliderHit ) {
var slope : float = Vector3.Angle( hit.normal, transform.up );
if ( slope >= minSlideSlope slope < 90 ) {
sliding = hit.normal;
if ( sliding.y == 0 ) sliding = Vector3.zero;
} else {
sliding = Vector3.zero;
slideSpeed = 1.0;
}
/* This part lets you slow characters as they try to walk up steep, but not too steep, slopes.
// to use it you need vars minSlideSlope, maxWalkSlope, and hinderMovement (a multiplier applied in .Move to slow the character)
slope = Vector3.Angle( hit.normal, targetMovement - Vector3.up * targetMovement.y );
if ( slope > 90 ) {
slope -= 90.0;
if ( slope > minSlideSlope ) slope = minSlideSlope;
if ( slope < maxWalkSlope ) slope = 0;
hinderMovement = (minSlideSlope-slope) / minSlideSlope;
} else {
hinderMovement = 1.0;
}
/**/
}
function Jump() {
if ( onGround sliding == Vector3.zero ) {
// okay to jump
}
}