Saturday, April 23, 2016

game maker - How to make a more accurate lap time? get_timer() LIMITATION?



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.



Answer



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..


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...