How do I spawn an object from family with a container object

  • Hi everyone,

    Firstly, I'd like to introduce myself. I picked up a personal license of Construct 2 and I'm enjoying playing around with it during my holiday break. I apologise that I'm still getting to grips with the software as I've had it for a few days. I appreciate any help you can throw my way.

    I'm trying to make a simple top down car game in which:

    a) The road is scrolling downward giving the player the illusion that he/she is driving at speed (just a top down 8direction movement) - This works.

    b)Every 3 seconds, random Cars spawn and scroll downward (but they are facing up, making the player think he's overtaking them on a highway). (I've got different sprites for different cars and I've put them all into a family. - This works.

    c) If the player's car hits the car, an explosion animation plays and he loses a life - This works.

    d) The player gets points by tailgating the cars (riding close behind them as they scroll down) - This is what I'm still working on.

    My solution so far to try to spawn a 'hitbox' sprite that follows behind the cars after they spawn. The Hitbox will be invisible once the code works. The problem is that my code spawns the hitbox for the first car that spawns, but as soon as the next car spawns, the hitbox warps to the next car. (This is because every tick I'm setting the position of the hitbox to the 'Cars' family. As soon as the next car spawns, the hitbox moves. I need a unique hitbox for each car, but I'm having trouble because the cars are in a family. I'm not sure what the event sheet code would be to ensure that:

    a) For each car that spawns randomly, it has it's own unique hitbox that follows it.

    b) If the player is inside that hitbox, he/she gets points. (This I was able to do when my game only consisted of one car, but when I progressed to making the game spawn random cars from a family of them, it became more complex).

    I feel overwhelmed and humbled by how people here are capable of solving complex problems that make my little game look very simple indeed. Any help would be greatly appreciated.

  • Perhaps it would simply be easier to have the player's car have a hitbox in front of it, so that it could detect cars ahead instead of the other way around?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Perhaps it would simply be easier to have the player's car have a hitbox in front of it, so that it could detect cars ahead instead of the other way around?

    You know.... it sounds simple when you say it, but that's a perfect solution. I completely overcomplicated my program. Thanks very much for your input. Feeling pretty stupid.

  • Oh good, I felt kinda bad because I didn't actually help solve the problem and instead peddled an alternative, lol

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