[Solved]Annoying collisions caused by unprecise coordinates!

0 favourites
  • 12 posts
  • In my platformer game the player is supposed to push blocks into gaps in order to traverse them but I can't get it to work properly because any object moved does not have precise x and y coordinates. Pixelrounding does not help.

    Any ideas?

    Thanks!

  • You could try something like int((sprite.x*youroffset)/youroffset)

  • You could try something like int((sprite.x*youroffset)/youroffset)

    Can you please explain that? :/

  • You would set the x coordinate, when moving, to the closest x within range, using that formula.

    That is if the offset is bigger than one.

    Otherwise just use set x to int(self.x)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • A couple ideas come to mind. One is to dynamically create some extra walls to help to box fall into the hole. Another is to check if there’s a hole below a box and have it shift a bit to align with it to drop in.

    The second idea seems a bit simpler to do. If everything is aligned on a grid then it’s a bit easier. So say the blocks are 32x32 and the ground is a grid of those boxes. I’m also assuming the boxes have their origin centered. You can calculate the closest grid position the box is on with:

    gridx=int((box.X-16)/32) *32+16

    gridy=int((box.y-16)/32) *32+16

    Then to see if there’s a hole below it check the point (gridx, gridy+32) to see if it’s overlapping anything.

    If it’s not you can then check if the x difference is close enough to make it shift into the hole. Here it would move into place if it was within 4 pixels.

    Compare Gridx > box.x

    Compare gridx-box.x <4

    — set x to min(box.x+1, gridx)

    Compare gridx<box.x

    Compare box.x-gridx <4

    — set x to max(box.x-1, gridx)

  • R0J0hound That is way too much math science for me, I just want to push a block into a hole in the ground and then push another block across the hole *sigh*

    I'll link the c3p file if anyone would care to have a look.

    1drv.ms/u/s!AjgxVO4vN9p6g8sER4ZmLsPoJLXyWQ

  • Just use force! if box is above hole and should fall into hole, but doesn't, then just put it there. If you want box fall/go into hole by itself, it could disagree and get stuck behaind some pixel.

    If you can't kick box over the holes, then you could just check if box x is Equal or bigger then hole x and then box it into hole.

  • Just use force! if box is above hole and should fall into hole, but doesn't, then just put it there. If you want box fall/go into hole by itself, it could disagree and get stuck behaind some pixel.

    If you can't kick box over the holes, then you could just check if box x is Equal or bigger then hole x and then box it into hole.

    Well just for the sake of it I tried make the same thing in Game Maker Studio using gml code and it already works the way it should. I'm gonna try and make the same logic with construct 3's event system.

  • I tried your example, works like it should. Only its bugs when players starts to push box over other, you should disable platform behavior on box that fell into hole, so player can't push 2 box same time and get stuck, because box in hole can't move.

  • I tried your example, works like it should. Only its bugs when players starts to push box over other, you should disable platform behavior on box that fell into hole, so player can't push 2 box same time and get stuck, because box in hole can't move.

    Tried what you said but sadly it didn't change anything. Player can still get stuck on the box in the hole by him self or while pushing the other block over it.

    Thanks for the effort though :)

  • I was playing with your example and came back to post, and saw that SnipG had the same idea I had...

    The problem is that the platform behaviour makes the box push up from the floor, so its Y value is not the same as the ground on either side (by a tiny fraction of a pixel). This could be considered a bug...

    anyway, I made a sample that turns off the platform behaviour and rounds off the Y value, and then it works the way you would expect. If you round the Y value without turning off Platform, then the box just pushes up from the floor again.

    In my sample, you can click on a box to see what its Y position is. When the box gets locked in position I change the animation so you know it can't be moved anymore...

    https://www.rieperts.com/games/forum/boxdrop.capx

    other options would be to not use the Platform behaviour for the boxes - use physics instead (but that has its own problems sometimes), or create your own manual system to push boxes around...

  • AllanR Thankyou very much! I think I actually got it working now. I just told the boxes that when they are by a wall (works with boxes and walls since they are all solid) I disable platform movement then set y to int(y) + 1. So far it seems to work fine.

    Thanks to all for your helpful contributions :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)