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

Get help using Construct 2

Post » Sat Jul 11, 2015 1:10 am

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.
B
5
Posts: 10
Reputation: 255

Post » Sat Jul 11, 2015 1:25 am

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?
B
52
S
24
G
18
Posts: 295
Reputation: 13,090

Post » Sat Jul 11, 2015 1:31 am

Sup with that? wrote: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.
B
5
Posts: 10
Reputation: 255

Post » Sat Jul 11, 2015 3:03 am

Oh good, I felt kinda bad because I didn't actually help solve the problem and instead peddled an alternative, lol
B
52
S
24
G
18
Posts: 295
Reputation: 13,090


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 31 guests