0
\$\begingroup\$

In the room there are 22 cars. All cars have a different speed.

The cars are numbered from 1 to 22 with the help of the variable carNumber.

CODE - obj_Car / Set car speed (Create Event):

velocity=10-((carNumber-1)*0.01);

Here's how there is a difference in car placement near the end of the lap:

enter image description here


However, even with this difference, the times of many cars are repeated:

enter image description here


The detection of lap time looks like this.

CODE - obj_Car / Time lap (Collision with obj_Finish) :

other.orderLapTime[car]=get_timer()-other.discount;

  • Discount = this is the exact time when the room starts (cars already start running).

CODE - obj_Finish / Set discount (Create Event):

discount=get_timer();

The display is made with a modifier (multi, to simulate actual track times).

CODE - obj_Finish / Draw time lap (Draw Event):

draw_text(1500,100+(20*(i)),string_format(orderLapTime[i]*obj_Seth.multi/1000000,1,3));

Even taking the multiplication and increasing the number of decimal places, there are still many repeated times:

enter image description here

Some inconsistencies including. Cars with slower speeds marking faster times.


I could slow down the base speed (10) to solve such a problem, but I already think in the long run. The races can't take so long. In addition I intend to give the player the option to set the speed with which the race takes place (a multiplier, more frames, etc).

It could also increase the difference between the speeds (0.01 to 0.05), but I would like a general resolution, so that I can notice through the lap time, if only by one thousandth (0.001).


EDIT 1 - Attempts made based on answers and comments from Bálint and TomTsagk:

That is what I tried to do.

CODE - obj_Car / lap time (Step Event):

unit+=velocity/60*0.001;

Below the results...


enter image description here

Respective code:

draw_text(1500,100+(20*(i)),string_format(orderLapTime[i],1,3));

enter image description here

Respective code:

draw_text(1500,100+(20*(i)),string_format(orderLapTime[i],1,5));

The speed difference between the cars is 0.01.

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

Your problem seems to be that you only check whether any cars have passed the finish line in every frame. Since the game has a fixed time-resolution (60Hz) it really can't tell the difference between a lot of cars. (In your second example, the difference between a lot of the displayed times are a millionth of a second, which is a microsecond, which is probably due to code execution and the general slow speed of clocks with microsecond resolution).

What you'll need to do instead is check exactly when they cross the line. The easiest option would be to just start stepping between the frames with 1000th of a second steps, each time moving the car just a tiny bit (speed in units / second * 0.001s). You'll know the exact time any car passes by counting how many steps it took to reach the goal, dividing it by 1000 and adding it to the current frame time.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ The easiest option would be to just start stepping between the frames with 1000th of a second steps, each time moving the car just a tiny bit wouldn't it be better if on the frame that a car crossed the line, the game could calculate the distance from the car to the line (before crossing it) to "predict" the end time? \$\endgroup\$ Commented Nov 1, 2019 at 10:30
  • \$\begingroup\$ The finish is an object whose sprite measures 16x16. Lap time is measured when the car collides with the arrival. \$\endgroup\$ Commented Nov 1, 2019 at 22:42
  • \$\begingroup\$ If I understand what you said, I put a step event in the cars, in it a variable is increased by 1 every step. Still the times repeat themselves. \$\endgroup\$ Commented Nov 1, 2019 at 22:44
  • \$\begingroup\$ I used the formula you passed, I must be wrong in some detail. What you say makes sense, but I'm not getting the expected result. I added my attempts to the question. \$\endgroup\$ Commented Nov 1, 2019 at 22:48
0
\$\begingroup\$

The solution I found, you should count the time using the step event at the finish line.

obj_Finish - step event:

timer+=1;

And when the car collides with the finish line, just add to the timer result the distance between the origin of the car and the origin of the finish line.

obj_car - colision with obj_finish:

distance=point_distance(x,y,other.x,other.y);
lapTime=other.timer+distance/10;

That way, even if multiple cars with different speeds collide with the finish line in the same frame, the distance from each to the finish line will be different, so the time will be different.

The division by 10 made the calculation value correct, so that I could order the cars..

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .