Positioning

Get help using Construct 2

Post » Sat May 27, 2017 8:07 pm

Hi guys I, :) m creating a racing game and i have AI cars but how do I tell the player what position there in does anyone have a capx for this? :D
Image
B
20
S
10
G
10
Posts: 229
Reputation: 7,624

Post » Sun May 28, 2017 3:25 pm

Hi @LaurenceBedford, assuming you have a looped track, this might work, haven't tried it out yet though:

Create a sprite object called "trackSection" and give the object two instance variables called "position" and "sectionNo" Place instances of this sprite contiguously around the track setting sectionNo=1 to the first section and stepping up by one for each subsequent section. You can set the sprites invisible.

Give your cars instance variables of "sectionNo" and "position" as well, starting both on 0.

Use this code:
If car is overlapping with trackSection & car.sectionNo<trackSection.sectionNo, trigger once:
set trackSection.position to self.position+1
set car.position to trackSection.position
set car.sectionNo to trackSection.sectionNo

As each car passes over the section it tags itself with the current position value of that section which steps itself up for the next car. Tagging the car with the current section number and checking to make sure that it's less than the current section that its on prevents bugs from the cars backtracking into a previous section.

Essentially what you're doing is running a sequence of small races and check the winner for each section. You want to keep each section fairly small so that it captures place changes quickly.
B
16
S
7
G
3
Posts: 396
Reputation: 3,700

Post » Sun May 28, 2017 3:27 pm

In fact the track section sprites don't need to be touching, as long as each spans the width of the track and they're deep enough to register a car passing at speed i.e. the car isn't moving further than the depth of the section in a single tick.
B
16
S
7
G
3
Posts: 396
Reputation: 3,700

Post » Sun May 28, 2017 4:09 pm

@mekonbekon sounds good ill try if you visit my profile and play my racing game you will see the set out
Image
B
20
S
10
G
10
Posts: 229
Reputation: 7,624

Post » Mon May 29, 2017 9:11 pm

@LaurenceBedford

This is the basic idea:

https://www.dropbox.com/s/2tmcnhi1mngfe ... .capx?dl=0

The code I discussed above is in Event 2; the rest of the code is only there to get the cars moving.

You can make the positioning more accurate by adding more trackSections in.

Hope that helps! :)
B
16
S
7
G
3
Posts: 396
Reputation: 3,700


Return to How do I....?

Who is online

Users browsing this forum: Syazanie Amirin and 6 guests