apply_central_force is being ignored on RigidBody3D

Godot Version

4.3

Question

I have been working on this problem for awhile now and am stumped. I have a boat (RigidBody3D) that I am trying to move with apply_central_force. Unfortunately, everything seems to be working except apply_central_force. Turning works and I am able to set the speed variable fine as well, but it seems like the one line where I apply force is simply being ignored. Here is the relevant code snippet I am working with from the boat’s script.

extends RigidBody3D

@export var controls:Resource = null

var speed := 0.0
var acceleration := 1000

var handling := 25
var turning = 0
	
func _process(delta: float) -> void:
	turning = 0
	turning += Input.get_action_strength(controls.move_left)
	turning -= Input.get_action_strength(controls.move_right)
	turning *= deg_to_rad(handling)
	
	speed = 0
	speed += Input.get_action_strength(controls.move_up)
	speed -= Input.get_action_strength(controls.move_down)
	speed *= acceleration

	var new_basis = global_transform.basis.rotated(global_transform.basis.y, turning)
	global_transform.basis = global_transform.basis.slerp(new_basis, 3 * delta)
	global_transform = global_transform.orthonormalized()

func _physics_process(delta: float) -> void:
	apply_central_force(global_transform.basis.z*speed)

global_transform.basis and speed both print out correct values in the physics_process function when I test, but the boat just does not move. Damping is set to 0 on the boat. I have tried using apply_force as well and had no luck.

Might have more luck with overriding _integrate_forces and using it’s state.apply_central_force

Thanks for the reply. Unfortunately, that didn’t resolve it. It is still stuck ignoring all forces on my RigidBody3D. I actually tried to apply some gravity to it and the RigidBody3D ignores gravity as well.

all forces? Is your rigidbody locked on any/all axis? is your game paused?

No forces are affecting it and no axis are locked. I have a cannonball right next to it that drops down fine as well. I have isolated the problem to these three line of code as when I commented them out, the boat drops into oblivion just fine:

var new_basis = global_transform.basis.rotated(global_transform.basis.y, turning)
	global_transform.basis = global_transform.basis.slerp(new_basis, 3 * delta)
	global_transform = global_transform.orthonormalized()

I was trying to convert this velocity/vector boat I made into a simpler version using transforms and global_transform.basis for movement. I’m probably doing something horrid here as I am not as familiar with Basis and am trying it out.

I switched over to a CharacterBody3D and it is working fine now. I am guessing there is some issue with RigidBody3D that I was messing up. Thanks for your help though.