• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

physics objects clamped to room strange collision masks

S

Stratos.la

Guest
so i have some boxes that pop up and tried clamping them to the room. even though i have set the collision mask and physics collision shape to the exact size when they get to the sides of the screen they stop in their x ( middle_center) .i cant seem to figure out why! when they collide with each other they stop right on their edge just fine.

step event code for clamping
GML:
phy_position_x = clamp(phy_position_x,camera_get_view_x(view_camera[0]),camera_get_view_x(view_camera[0]) + camera_get_view_width(view_camera[0]));
 
S

Stratos.la

Guest
Are you accounting for the width of the sprite?
Ummm noooo... but shouldn't the collision shape involve that too? The sprite editor is also setup in the correct size.or is it like this because of the center pivot?
 

Nidoking

Member
You're using the function clamp. clamp has nothing to do with physics, sprites, instances, or anything else. It returns the first argument, if it's between the second and third arguments, or the second or third argument, whichever is closer to the first argument. In the context of the function, none of those numbers are necessarily positions. If you want the box to be half a sprite width from the wall, you have to clamp it to half a sprite width from the wall.
 
Top