# 2D Boundaries and Colliders

Hello,

I am working on a 2D game that the levels have I would guess is form of isometric view. Characters can move up, down, left and right and games of view and character movement reference could be games like, River City Ransom, Battletoads, Turtles in Time. How would I go about having the top of the level act like a collider and prevent players from leaving the space yet still allow them to jump once the boundary is reached.

Thanks

So you just want to clamp them into the game area (based on the floor area) then they exit off the ‘top’ of the screen? You could have a collider around the edges, you could use the clamp function, you could have walls/trees/rocks/water etc with collides. There’s a number of options, you need to look at the level design for each level & use what is best.

So character movement would be clamped within Y coordinates of the yellow arrow. Pink line is the boundary of where character would stop but would still like to have it jump to a max height of the green line. Wouldnt clamping prevent that jump since you are reaching the distance allowed in the clamped range?

I’ve never done this so will just throw an idea out there, hopefully someone with more experience will jump in with a proven solution for you because I’d be interested in learning as well.

Could you put one of those one sided colliders in at head height so it stops the player moving to far up screen & then ignore it if the player hits the jump button? Maybe have a bool that says the player is grounded, then make it false when the player hits the jump button & change it back to true when they exit the collider?

Or clamp the y coordinate if the bool is true, unset it when you jump, then reset it when the y coordinate is < the normal clamp height. E.g.
clampHeight=5;
heightClamp=true;
canJump =true;

If(<insert check for hitting the jump button && canJump){
heightClamp=false;

canJump=false;
}

If(!canJump && player.transform.position <=5) {
heightClamp= true;
canJump=true;
}

If(heightClamp) { }

Sounds like a good idea, only issue I might see is if player jumps then hits the up button it will move past the collider. Then when character lands it will be standing on it.