Change position of VehicleBody3D in GDScript to reset tumbled car

Godot Version



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?


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 :slight_smile:

func _integrate_forces(state):
	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

triggerRecover is set to true by the corresponding Input.is_action_pressed()
Found this solid summary what you can do with _integrate_forces()

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.