• 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!

How do you stop a moving Object at a Precise pixel?

E

EqualiteGem

Guest
So here's the problem I would greatly appreciate it if someone can solve it. The breadstick is falling
at a speed of 12px (speed = 12) from above. By the time I can check for a collision between the 2 white lines on the bread it is off by 2pixels. The higher the speed the more inaccurate and off the pixels are for checking collision between the two white lines on the bread before the hand grabs it. So how do I get precise pixel collision (not above or below the white line but but the hand has to be between the two lines for it to be correct?)
test_picture.png
 
E

EqualiteGem

Guest
The collisions only work perfectly when speed = 1 or 0 by the way.
 

Miradur

Member
Hi, maybe this video will help you:



In principle, you simply have to query a collision pixel by pixel and then make the actual movement
with your 12 pixels.

Miradur
 

Neptune

Member
Here is what you do: do your collision check with your speed factored in (place_meeting(x,y+12,o_wall))

And if youre colliding, you dont move 12 pixels, instead you run a while loop that adds 1px until youre snug against the collision, and then you stop moving until the conditions allow otherwise.

EDIT: If your speeds are incredibly fast, then you may need something like the above video, where you do your collision checks in iterations (doing the checks in a 'for' loop)
 
E

EqualiteGem

Guest
Thank you both (Vether and Miradur) for your responses I'm going to try to implement these and see if they work.
 
Top