Godot Version
v4.6.stable.official
Question
So I was experimenting with gdscript a bit and and I tried to remake the default character body movement script in to a rigid body movement.
When I run the script in func _process(delta: float) it behaves sort of ok,
but when I run the function in func _integrate_forces(state) I sometimes get stuck somehow and can’t move after landing from a jump.
This confuses me since I have heard that func _integrate_forces(state) is better used for handling physics.
This is the script used for func _process(delta: float)
func move_on_ground_proc():
if Input.is_action_just_pressed("ui_accept") and ground_ray.is_colliding():
apply_central_impulse(Vector3(0,JUMP_FORCE,0))
var input_dir := Input.get_vector("left", "right", "forward", "back")
var direction := (head.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
apply_central_impulse(Vector3(direction.x,0,0) * SPEED)
apply_central_impulse(Vector3(0,0,direction.z) * SPEED)
and this one is for the func _integrate_forces(state)
func move_on_ground(state: PhysicsDirectBodyState3D):
if Input.is_action_just_pressed("ui_accept") and ground_ray.is_colliding():
state.apply_central_impulse(Vector3(0,JUMP_FORCE,0))
var input_dir := Input.get_vector("left", "right", "forward", "back")
var direction := (head.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
state.apply_central_impulse(Vector3(direction.x,0,0) * SPEED)
state.apply_central_impulse(Vector3(0,0,direction.z) * SPEED)
also here is my object hierarchy
