How do I make multiple objects move together?

0 favourites
From the Asset Store
This is a code so you can see the same skin on all screens (peers). Each peer gets a skin, in addition to 4 directions t
  • Hello,

    I would like to move multiple object in the same time.

    I use tile movement as the game use grid. But sometimes the object don't go at the right position.

    Especially when two object follow each other. The second don't move as it consider the case occupy with a solid object

    Is there a simple solution to this problem.

    Someone told me to use json and array to calculate the position but i don't get how do it?

    Thanks

  • What's the problem? They should move together and you don't need the for each btw

  • They don't move exactly as I want. When two object are near each other they don't move together after.

    For exemple here, when I go right only one go right and the second wait.

    I cannot insert gif or video?

    Here red and blue are near each other

    I click on right and only blue move

  • I don't see how that could happen if they are all moving together. They have different speeds? Did you give them a solid behaviour?

  • They have solid and tile movement behavior. Same speed.

    I think the problemis during the movement the second onnecalculate that there is a solid object where he should move so he doesn't move.

  • Yes exactly remove the solid behaviour

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes exactly remove the solid behaviour

    In the gameplay, theobject will be stop by wall and some others things.

    How can I do when they should be stop by a solid object like a wall?

    If I remove the solid behavior?

  • I think you can make the wall solid then it won't move into that tile occupied by the wall?

  • I think you can make the wall solid then it won't move into that tile occupied by the wall?

    But I also need to give a solid behavior to my objects

  • I don't think there is a simple solution to this problem, it's a pretty classic issue with pathfinding and collisions.

    A common solution is to disable collisions/solid behavior during movement. That is probably the easiest way out, and also quite effective for most people's purposes.

    Otherwise, you're looking at predicting the future position of each object, and probably also a queue for each position since there can still be conflicts. I don't know how exactly to go about doing this, but there are algorithms out there, specifically the parts regarding leader following and queueing. Those articles are not for tile based movement, but any concept regarding grid coordinates can be applied to tiles as well.

  • You may be able to set solid collision filtering with the tags to make the family ignore collisions with itself, try it!

  • You may be able to set solid collision filtering with the tags to make the family ignore collisions with itself, try it!

    I cannot because i risk to end with many object in the same place with superposition.

    I try to make a loop to make the "object" move by lines.

    When go "up" The first line move, after the second line moves, after the third... and so on

    But it fails

  • One solution is to remove the solid behavior completely and do your collision detection yourself. An array can be useful for this since its grid based. Then you fill the array with wherever the objects are. The trick is when you move an object to update its position in the array to the goal position so it’s old position is free for other objects to move onto.

    The setup of the array could look like this:

    Start of layout:

    — Array: set size to (layoutWidth/32, layoutHeight/32, 1)

    ——array: for each xy

    —— compare tile at(array.curx,array.cury)=-1

    ———array: set (array.curx,array.cury) to 1

    —— for each fmotion

    ———array: set (fmotion.x/32,fmotion.y/32) to 1

    Then before simulating moving left for instance, you’d check if that spot was free, and if it was simulate the key press and update the array.

    Array at (fmotion.x/32-1, fmotion.y/32) =0

    — fmotion: simulate left pressed

    — array: set (fmotion.x/32, fmotion.y/32) to 0

    — array: set (fmotion.x/32-1, fmotion.y/32) to 1

    It would be very similar for the other three directions. You’d use that with the for each ordered logic you already have.

    That’s at least one idea. There may be clever ways to make it simpler. The issue with the solid behavior is it doesn’t know how to handle moving objects.

  • On further thought you can avoid the array entirely. You just need another sprite for each moving sprite to be for collision detection. The idea is that additional sprite is where the moving sprite will be going and can be used for collision detection.

    Here's a c2 example that can load into c3. The tilemovement behavior isn't in c2 so i did it with events.

    dropbox.com/s/mnci1fyhtbimjlm/grid_motion.capx

  • Then before simulating moving left for instance, you’d check if that spot was free, and if it was simulate the key press and update the array.

    Sometimes the spot won't be free because another "mouton" would be in the spot. But this "mouton" will move to and make the spot free after his movement.

    I have an array with all the curent position of my object. I think i have to check in the direction of the movement if the a case would be "free" or occupy by an "obstacle". If it's a "mouton" i have to go to the next one.

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