How to measure acceleration from 0 to 100 kmh?

How to measure acceleration from 0 to 100 kmh?
I don’t want to use setTimeout and setInterval
I need some stopwatch like in unity maybe so enabled = false; and enabled = true; probably and then run the timer or other way?

So my proposed logic is to start the timer when accelerate and stop the timer when 100 kmh?
in pseudocode:
if(accelerate){
start timer
}
if(100kmh){
stop timer
show acc sec .ie 5 sec
}

What are you trying to do? As acceleration is change in speed over time, the acceleration from 0-10 is going to be the same as 0-100 assuming it’s constant.

Are you trying to measure the time it takes to get to 100kmph from a standing start?

yes like in car acceleration
I tried one day with setTimeout and setInterval but it’s not precise and different results shows, first try: 5 sec, second try: 6 sec
I just want to implement the stopwatch and tweak the acceleration parameter for example to get, 8 sec to 100 kmh

I meant acceleration time not acceleration of course

Once the car has started, start adding delta time in the update loop to a variable and stop when the car races 100kmph.

1 Like

As long as acceleration is constant you can work out the acceleration needed to get a 0-100kmph time though. No need to manually test it

1 Like

ok so how to workout the ‘accelerationFactor’ for 8 seconds for example?
I noticed this:
30 - 3.6 s
50 - 2.1 s
yes so 8 sec under 30 ‘accelerationFactor’ but dont know what exactly value

Hi @grzesiekmq,

You can monitor the linear velocity of your car rigid body to check when it reaches 100km/h. Assuming your PlayCanvas scene uses 1 unit for 1 meter, then:

100 km/h -> 27.78 m/s

You can use the length of the linear velocity to find out when it’s equal to that:

var linearVelocity = carEntity.rigidbody.linearVelocity;

if( linearVelocity.length() >= 27.78 ){

   // we hit 100km/h, stop counting time
}

Edit: 27.78 is the velocity per second, whereas the linear velocity length is per physics simulation step, so I think you will have to find the final number depending on how you count the speed. But the logic will be the same.

1 Like

Assuming acceleration is constant, the acceleration needed to a set speed in t secs is:

acceleration = speed to reach / t

2 Likes

yes sure just forgot about it :sweat_smile: