Spawned rigidbody object spins like spinning top

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rico345100

Here’s the code for spawning object which is rigidbody node:

func spawn_asteroid():
	var spawn_position: Vector3 = get_spawn_position()
	
	var asteroid_instance = asteroid_scene.instance()
	asteroid_instance.transform.origin = spawn_position
	spawned_asteroids.append(asteroid_instance)
	
	# Push towards player
	var direction_to_player: Vector3 = player.transform.origin - spawn_position
	asteroid_instance.add_force(direction_to_player * asteroid_speed, spawn_position)
	
	add_child(asteroid_instance)

There’s no add_torque or any additional codes to handle rotation, however when object spawned, it spins like spinning top.

First I thought that it caused if two rigidbody objects are intersected and push each other and cause rotation, but it wasn’t.

Have no idea why they are spinning. Is there a something that I missed? Unlike Unity, there’s no way to stop their rotation. Using Godot 3.1.1.

:bust_in_silhouette: Reply From: wombatstampede

The RigidBody will spin if you add the force to another position than (0,0,0).
add_force takes two parameters.
force: is the force vector which b.t.w. is “rotated” in global space/coordinate system.
position: is the position where the force is applied. This position is “rotated” in the global coordinate system but relative to the RigidObject.

In your case, you should be able to just pass Vector3() as second parameter.