0 Favourites

[SOLVED]Problem with unwanted collisions.

  • Hi!

    I try to make a tetris-like, but I've a problem, here's a picture:

    <img src="http://dl.dropbox.com/u/44390929/tetris.png" border="0">

    The sprites, with a 32px width, come into collision, despite the fact that they move by 32px on the X axis. So I don't know why they collide!

    Here a .capx of my test:

    test.capx

    Perhaps this is due to the platform behaviour?

    What do you think?

  • I downloaded the capx file and validated that this is an issue. I thought it might have something to do with the physics as I ran into a similar issue around scaling of images with Box2D a couple of months ago but it looks like you are not using them at all.

    I noticed that if you change the width/height to like 31.9 the issue appears to be resolved.

  • I can't change the width/height to 31.9 ... we're talking about pixel here!

    I guess it's because of collision mask, nope?

  • Well, I've change the collision mask in this way:

    <img src="http://dl.dropbox.com/u/44390929/dfdf.png" border="0" />

    And now that works!

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • But now I've a problem with horizontal movement, because of the fact I reduce the width of the mask. :/

  • I might have not indicated correctly what I did since I am still really new to the tool. I selected the Sprite object in the Object pane (lower right) and then adjusted the Height and Width elements under the Size properties. Not sure how that affected the sprite exactly.

    Your way was pretty interesting though to affect the mask but I can see how that would mess up your key press calculations.

  • I'm sure we should keep a round number to the width and height of the sprite, to not have a white padding between the sprite.

    (Btw I guess it's strange that we can set up something like 31.9 on the main panel, and can't do that when we edit the animation.)

    With the solution of reduce the collision mask I can resolve my main problem, but if I press left or right when the sprite who falls is near another sprite, then he can overlaps that sprite. I don't want that! Furthermore that causes some strange bugs:

    <img src="http://dl.dropbox.com/u/44390929/Sans%20ere1.png" border="0" />

  • Might try turning on pixel rounding. Or make your own using int(sprite.x/32)*32.

    Keep in mind 32x, 32y with the hotspot in the center will be off by 16 pixels.

  • I got the hotspot on the bottom-left.

    Turnng on pixel rounding works great to not have white padding when I try with 31.9px width/height, but not solve the problem of overlaping when I move on the left or right..

  • Unfortunately the only way to get collisions working reliably for the platform movement is to count adjacent objects as overlapping. So two 32x32 objects positioned at (0, 0) and (32, 0) count as overlapping. I'm afraid it's just something you have to work with - if it's changed so they don't count as overlapping, some weird platform bugs start appearing.

    As for a workaround, how about using a full-size collision mask, but setting the object size to 31.9 x 31.9?

  • It would probably benefit you not to use platformer behavior but design your own movement.

  • I would simply not use the platform behavior and do a stepped movement.

    As you have a stepped horizontal movement, I think it would be logical to have a stepped vertical movement.

    so

    Global vRate = 1  //speed of dropping
    every vRate seconds 
      -> Sprite : set Y to self.Y+32
    //sprite2 is just the inert form of sprite
    Sprite overlap Sprite2
      -> spawn sprite2
      -> sprite2 : set Y to self.Y-32
      -> sprite2 : set width to Sprite.Width
      -> sprite2 : set height to Sprite.Height
      -> destroy sprite
    system : sprite.count = 0
      -> create Sprite at X = floor(random(layoutWidth)/32)*32  Y=0

    This way you can even use vRate to modulate difficulty

  • It might be a good idea to not use built-in collision at all and rely on an array representation of the grid to create your own collision detection.

  • Hi all and thank you for your response.

    I must admit that I'm lazy, that's why I use PlatformBehavior, but with the worries that implies I give up this idea.

    With Ashley's explanations I realize it's not a good solution to base a simple game as Tetris on a complex system.

    I realize that making a stepped movement way is a better solution, a better start.

    Starting from scratch sometimes saves time ... I just lost more time trying to make the PlatformBehaviours set up my ideas than I will have wasted trying from scratch.

    Anyways, I'll post the final solution here, as it benefits everyone, although Yann gives me the solution on a plate!

  • And tadam!

    Everything works, finally just few events for doing that.

    Here is the file, hope that can help.

    tetris-like.capx

    Merci Yann!

    Press the spacebar to accelerate the fall of a sprite.

    And now I can continue this tetris-like in a good way.

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