Godot Version
4.5
The Problem
I have a player character (RigidBody2D) and I want it to be able to “hold” a box
hold = drag it in front of itself.
However…
- The box gets further and further from its intended position as the character moves, which is not intended.
- The box should face the same direction as the player, but I do not know how to do that.
Details:
Scene tree:
The scene tree again, but also with node positions:
Movement code:
Moving:
func _physics_process(delta: float) -> void:
var liike_suunta: Vector2 = Vector2.ZERO
liike_suunta.y = Input.get_axis("Pohjoinen", "Etelä") # Up and down.
liike_suunta.x = Input.get_axis("Länsi", "Itä") # Left and right.
liike_suunta = liike_suunta.normalized()
apply_force(liike_suunta * Nopeus)
Turning:
func _integrate_forces(state):
var hiiren_piste: Vector2 = get_global_mouse_position()
var kääntö_suunta: float = get_angle_to(hiiren_piste)
var kääntö_voima: float = kääntö_suunta * 400.0 * state.step
var pehmennys: float = pow(0.001, 5 * state.step)
state.angular_velocity += kääntö_voima
state.angular_velocity *= pehmennys
(I am not that good with physics.)
The question
How do I keep the box in front of the character, without it being completely static, or having the problems listed in the “The problem” -section?
Extra context:
I do not want the box to be static, since in my original plans for this thing, I wanted to detect if the box gets caught on something and then detach it from the character. (This project has a lot of moving parts and obstacles.)
End
I can also give out extra information, if needed.
Thanks in advance!


