• 3D
  • rotating rigid body with a fixed position in space

Hi, im trying to create a simple scene with two rigid bodies, one will be a table that can rotate in space the other just a ball: is there a proper way of doing this? I've tried using _integrate_forces(state) but the scene behavior is buggy, the table keeps jumping around, the code I'm using to rotate the table is as follows:

extends RigidBody

var rotation_dir = Vector3(0,0,0)
var RotSpeed = 0.01

func get_input():
	rotation_dir = Vector3(0,0,0)
	if Input.is_action_pressed("ui_up"):
		rotation_dir.x = -1
	if Input.is_action_pressed("ui_down"):
		rotation_dir.x = 1
	if Input.is_action_pressed("ui_right"):
		rotation_dir.z = -1
	if Input.is_action_pressed("ui_left"):
		rotation_dir.z = 1

func _process(delta):
	get_input()

func _integrate_forces(state):
	var Tform = state.get_transform()
	
	Tform.origin.x = 0
	Tform.origin.y = 0
	state.set_transform(Tform.rotated(rotation_dir,RotSpeed))
5 days later

You should not directly manipulate rigid-bodies unless they are set to kinematic mode. All other modes either behave as static and are not expected to move or their positions are being controlled by the physics engine (bullet)

Unless kinematic, also do not make them the children of any node moved.

That said if you want move a rigid body programmatically you should tell bullet to do it through add_force/torque or apply_xyz_impulse or set_axis velocity().

changes should be done in _physics_process() {}

The only other way is via joints where a kinematic manipulates a ridgid body via a joint.

https://docs.godotengine.org/en/stable/classes/class_rigidbody.html

You can consider making the table a kinematic if you expect to control its movement directly.

If you're going to use integrate_forces() you should know enough basic physics concepts like acceleration/force/velocity and how to manipulate them over a physics process step and something about how bullet does things.

For what you are doing I would recommend making the table kinematic or using add_torque()