Spawning 2 objects at same time problem

0 favourites
  • 7 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • So I have a moving object, when that object is killed, it spawns 2 new smaller objects. Issue I am having is, they spawn on top of each other, collide, and one of them shoots off into a random direction, when I want them both moving in the same general direction.

    Only way I found to avoid this was to use the move ahead action, but what I really want, is them to spawn side by side, relative to the angle they are moving at. Any help on how I might achieve this?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I am relatively new to Construct 2, but one thing I learned, is that one is shooting off because they can both collide with each other.

    So to prevent that you would have to disable their ability to mutually collide.

  • Now if I do that, then the 2 just sit on top of each other with collision being disabled, plus, I really just don't want them to spawn on top of each other is it, there may be instances where they may collide, and I want that to happen.

  • Here's an idea, I haven't tested it.

    You should be able to use the "Move at angle" action on the new objects when they spawn to move them away from each other in the direction you want.

    Description:

    "Move the object a number of pixels at a given angle in degrees."

    You'll want to get the angle that the original object is moving, then add 90 degrees. Spawn the first new object and "Move at angle" with that new angle by the new object's width for distance. (Or perhaps half-width if it spawns on its center)

    Then take the original object's angle again, and subtract 90 degrees. Spawn the second new object and "Move at angle" with this new angle, again by the new object's width for distance.

    If they still collide, add a bit to the width so that they don't collide.

    Alternatively, if you don't need the spawn placement to be variable, you could specify two image points on either side of the original object, and spawn your two new objects at those image points.

  • I made a picture to better represent what I'm trying to do.Or even better, if I could say let the 1st one spawn in it's default position, and the 2nd one spawn anywhere within a certain radius of the 1st one at a random value, but far enough away so it doesn't collide with the 1st one upon spawn. But at the very least, I would like to have the 2nd object spawn either to the left, or right of the original object, based upon the direction of travel.

  • Valhallen's answer really is the best way I can think of to do what you're doing. If you want them to spawn very close to each other, though, with maybe momentary overlap, you could just wait a very short amount of time to enable collisions (have the objects start without it). The downside of this is that they won't collide with anything within that initial short range.

  • Valhallen, that description sounds perfect. Now, the big question is, is there some way for the code to figure out the angle the original unit is moving at?

    So my code will know the objects angle of movement, then one new spawning object adds 90 degrees, the other subtracts, and they each move 25 pixels in their correct directions. What would that code look like, and what action would I be entering it under?

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