Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Lebweuh |
so been trying to limit my vehicle speed because it reaches speed of light and afraid if it can time travel so i came up with a solution like this
func _on_timer_timeout():
print(spd)
if spd >= max_speed:
engine_force_value = -1000
print("high")
else:
engine_force_value = 1000
it is partially works but not great.it basically brakes if speed is over speed limit. what should i use to stop my car from speeding over the limit? is there a better way to do it? (there is but i have no clue what it is please help me)
This might depend on how you’re accelerating, assuming some Input
value is applied to the engine_force
.
The simplest is to check the body’s linear_velocity.length() > max_speed
and ignore the Input
value, e.g. in _physics_process
:
engine_force = 0
if linear_velocity.length() < max_speed:
engine_force = throttle * delta
Beyond that, take a look at _integrate_forces
and alter the physics state there (which may be more complicated
spaceyjase | 2023-06-08 11:26