- Edited
hi, im trying convert a vehicle speed to a real speed. tried many ways but i cant do it. i think the thing is convert the speed float number (vector) to a integer, i dont know is this is possible, any ideas? sorry my english
hi, im trying convert a vehicle speed to a real speed. tried many ways but i cant do it. i think the thing is convert the speed float number (vector) to a integer, i dont know is this is possible, any ideas? sorry my english
Show us your code. How are you converting your speed?
2d project
acceleration = 500 maxSpeed = 1500 friction = 250 velocity = Vector2.ZERO state = move airState = false realSpeed = 0
//moving (acceleration) velocity = velocity.move_toward(input_vector maxSpeed, acceleration delta)
//moving (no acceleration) velocity = velocity.move_toward(Vector2.ZERO, friction* delta)
//brakes friction = 900
velocity = move_and_slide(velocity)
some like that
edit: is not a car, its a ship, and im using a kinetic body
@Binsk said: Show us your code. How are you converting your speed?
tried using the variables maxSpeed or accelaration, obviusly doesnt worked var velocity its like coords, i think have to extract the vector.y value looks negative and convert to int positive. no f idea in this point. xD
you can try to use vector
you can try to use get_linear_velocity()
@"David berg" said: you can try to use get_linear_velocity()
but thats for rigidbody, im using kinematicbody, perhaps i could chaange the player kinematic for a rigidbody MODE_KINEMATIC = 3 and linear_velocity works'???¿ i worked so hard on the movement system, have brakes, airbrakes, jumposystem with states and that stufff, and dont know how that code will work in a riogidbody but i think will give a try
I don't play with 2D, but the magnitude (length( ) in Godot) of a velocity vector should = the speed.
Another more fundamental approach could be to consider Speed = Distance/ Time. You have the position before applying movement and the position after applying movement, so can calculate distance from this while using delta as the time value.
This of course is in Godot units for distance (which you may need to apply a multiplier too depending on how your objects are scaled) and the delta step is going to be 1/60th of a second. Multiplying out both of these can get your KPH, M/s etc.
@Bimbam said: I don't play with 2D, but the magnitude (length( ) in Godot) of a velocity vector should = the speed.
F YEAH
func process(delta): realSpeed = velocity.length() // get the speed realSpeed = int(realSpeed) // convert to int number realSpeed *= 2 // this adjust the speed pretty good to my personal project speed print(realSpeed)
THANKS GUYS TODAY WAS A VERY F PRODUCTIVE DAY, BIG LOVE
Just as an aside, and totally down to personal preference/readability, but the above could also be written like:
realSpeed = int(velocity.length() * 2) #for rounding reasons I would probably apply multiplier before casting to int
print(realSpeed)
This is no more efficient (it's doing exactly the same calcs barring the multiplier adjustment), but may make your prototyping workflow faster .