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