DAShoe1 / Godot-Easy-Vehicle-Physics

A ray cast based vehicle for Godot 4.0
MIT License
112 stars 6 forks source link

Initial `local_velocity` increases futher from scene origin, with crazy results #5

Closed citizenken closed 4 months ago

citizenken commented 4 months ago

When I initially spawn my vehicle controller + vehicle nodes, the local_velocity seems to be calculated relative to the scene origin, which causes a crazy high local_velocity. As a test, I spawned my node at (0,0,0) and there was no movement, again at (10, 0, 10) and see some slight drifting, then again at (200, 0, 200) which results in the car flying off crazy.

I think the issue is this line, where its trying to lerp from the initial position to (0, 0, 0)

Spawned at (0, 0, 0):

# ((global_transform.origin - previous_global_position) / delta) * global_transform.basis
(0, -0.081668, 0)
# initial local_velocity
(0, 0, 0) 
# calculated local_velocity
(0, -0.041, 0)

Spawned at (10, 0, 10):

# ((global_transform.origin - previous_global_position) / delta) * global_transform.basis
(1200, -0.081668, 1200)
# initial local_velocity
(0, 0, 0)
# calculated local_velocity
(599.9999, -0.040834, 599.9999)

Spawned at (200, 0, 200)

# ((global_transform.origin - previous_global_position) / delta) * global_transform.basis
(24000, -0.081668, 24000)
# initial local_velocity
(0, 0, 0)
# calculated local_velocity
(12000, -0.040834, 12000)

I tested this on the demo_arcade scene spawning the car in various positions without the same effect.

Any idea on what could be up about this? It's a pretty big issue at this point. Thanks!

citizenken commented 4 months ago

I realized that I was setting the spawn position after the initialize call. I was able to fix this by setting a spawn_point property on the node, and setting global_position before calling initialize. Nevermind!