c++ - Colliding with obstacles on a map -
i'm trying make obstacles stops player after colliding. simply, walls.
i've created collision detection, this:
if (x > (wall.x1 - wall.boundx) && x < (wall.x + wall.boundx) && y >(wall.y1 - wall.boundy) && y < (wall.y + wall.boundy)) { x = 0; y = 0; }
but, can see, returns player object (0,0) on map (by way, i'm using mouse control character). want stop right collides , unable move through wall.
how can that?
you need separate if
statement handle each wall separately, , set x
or y
position bounds of wall:
if (x > wall.x1 - wall.boundx) x = wall.x1 - wall.boundx; if (x < (wall.x + wall.boundx)) x = wall.x + wall.boundx; // etc
no matter how far mouse attempts move past bounds of wall, remain @ position.
Comments
Post a Comment