How do I row movement?

0 favourites
  • 5 posts
From the Asset Store
Run and Jump in 3 Dimensions! Take your platformer to the next level!
  • Hello everyone.

    I am trying to make a move "in line". The sprites go to the right, when they collide with a wall, they "go down" 32px and do the reverse movement and so on. The problem is that during this process the distance X between changes randomly whenever they "dex 32px". I can't solve it, does anyone have any idea how to solve this problem?

    My file is here if anyone wants to see it.

    drive.google.com/open

  • This is an interesting problem.

    The main issue here is that depending on frame rate, dt and bullet speed, you will trigger the overlap condition at different X locations on each wall. If you look very carefully (or look carefully and increase bullet speed), you will see that sometimes the squares overlap the walls by different amounts before they change diection, then they will start at different locations and change the spacing.

    To make it look more consistent, one idea is to detect how much the overlap is and set the block back to where it 'should' be when it reflects back in the other direction.

    Try this and let me know how it works in your testing. The formulas can be simplified, but I left them as is, so it would be easier to see what the calculations are doing.

    It does start to fail if you increase the bullet speed to be so high that in one frame two squares would overlap the wall, if you need to deal with that case, you will need to do more work.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hmm, very good. I had not thought of that. I used his idea, but without the mathematical formula, I just added which X he should get when he collides. However, if you increase the speed to 500, for example, the error persists, but I won't use a bullet that fast, so it might work. Thanks.

    But I was thinking here, maybe this is not the best way to make elements move "in line", but I couldn't find a solution other than that.

  • My solution without the bullet behavior. You need an instance variable speed in square, but you can make the squares as fast as you want. Don't know if this is what you wanted.

  • since your squares and walls are a factor of 32 pixels apart, another option would be to set the x to the nearest 32 pixel boundary:

    x = round(self.x / 32) * 32

    I also tried speeding up the squares as they drop down a line, but they gradually get farther and farther apart because they are at different speeds for short periods of time.

    if maintaining the space between them is important, then you might want to use an array to hold all the positions of the "head" square, and set the following squares to a relative place behind the head...

    I helped someone with that concept who was making a worm game:

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

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