Godot Version
4.2.1
Question
Every now and then I take a too close turn with my VehicleBody3D and it tumbles over. Now I want to reset its position to 3m above ground and reset all its directions to 0.
I have tried to use
%Forklift.rotation = Vector3(0, 0, 0)
%Forklift.position = Vector3(20, 20, 20)
but that does not have any effect. Is there another way to reset it?
Max
mrcdk
January 7, 2024, 5:44pm
2
Try doing it in the RigidBody3D._integrate_forces()
function. Do it in the state
parameter.
1 Like
Thanks for the hint! I have implemented it like this to also take out the velocity of the vehicle
func _integrate_forces(state):
#https://gamedevacademy.org/physicsdirectbodystate3d-in-godot-complete-guide/
if triggerRecover == true:
var new_transform = state.transform
new_transform.origin.y = 5
new_transform.basis = Basis(Vector3(1, 1, 1).normalized(), 0)
state.transform = new_transform
var velocity = state.linear_velocity
velocity = Vector3(0, 0, 0)
state.linear_velocity = velocity
triggerRecover = false
pass
triggerRecover is set to true by the corresponding Input.is_action_pressed()
Found this solid summary what you can do with _integrate_forces()
system
Closed
February 6, 2024, 10:57pm
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.