_intergrate_forces is never called

Godot Version

Godot v4.6.stable

Question

I'm using rigid bodies for the first time and i've been setting all the constant forces and such in _physics_process as it works for me.

I’ve been seeing everywhere that _intergrate_forces should be used for this as anything directly affecting the objects physics state should be handled there since you have access to it’s state.

I got into this by following the _look_follow function in the rigidbody documentation.

My problem is that anytime i use _intergrate_forces it never seems to be called, at all.

Looking through solutions, I’ve seen that it is never called when asleep, but can sleep i turned off, i gave it a test object a floor to collide with, if i try to put the print and look_follow functions in an if statement which is checking if ui_accept is pressed, it is not called.

Any help here?

For code, this is exactly what is written.

extends RigidBody3D

var speed := 0.1

func _physics_process(delta: float) -> void:
	print("print1")

func _look_follow(state: PhysicsDirectBodyState3D,current_transform:Transform3D, target_position: Vector3) -> void:
	print("Hello2")
	var forward_local_axis: Vector3 = Vector3(1,0,0)
	var forward_dir: Vector3 = (current_transform.basis * forward_local_axis).normalized()
	var target_dir: Vector3 = (target_position - current_transform.origin).normalized()
	var local_speed: float = clampf(speed, 0, acos(forward_dir.dot(target_dir)))
	if forward_dir.dot(target_dir) > 1e-4:
		state.anglular_velocity = local_speed * forward_dir.cross(target_dir) / state.step
	

func _intergrate_forces(state:PhysicsDirectBodyState3D):
	#if Input.is_action_pressed("ui_accept"):
	var target_position = $"../Target".global_transform.origin
	_look_follow(state, global_transform, target_position)
	#linear_velocity += Vector3(1,0,0)
	print("Hello")

The virtual function’s name is _integrate_forces(). Without an r before the g.

2 Likes

I don’t like to copy paste to try understand what i’m typing, thanks for catching my stupidity.

1 Like

Avoiding copy and paste is good, but use your text editor’s tools such as autocomplete. If you are using an external editor you can hook it up to Godot’s built in LSP

3 Likes

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