RigidBody2D forces applying in unexpected direction

Godot Version

Godot 4.1.1

Question

What I’m trying to achieve here is to make my character move towards a raycasted point, as a sort of grappling hook, or magnet.

I’m trying to do this by getting a vector2 from the function ‘.get_collision_point()’ from a RayCast2D and applying as a force on a RigidBody2D using ‘apply_central_force()’. Instead of having my character move towards the collision point, he just shoots of into the top-right of the screen…


I suspected that this was because my RayCast2D was a child of the RigidBody2D, which was the cause of an issue i was having when trying to place a marker for the collision point, but i’ve tried making the RayCast2D a sibling instead, and tried making the RayCast2D an instantiated scene, but when i do that, no collisions showed up at all (I made sure the positions were correct).

here’s the code:

if Input.is_action_just_pressed("HOOK") and not hooked:
		
		ray_cast_2d.target_position = to_local(get_global_mouse_position())
		ray_cast_2d.force_raycast_update()
		
		if ray_cast_2d.is_colliding():
			HOOK_POS = ray_cast_2d.get_collision_point()
			
			
			var collider = ray_cast_2d.get_collider()
			if collider.is_in_group("hookable"):
				hooked = true
			
				#Instantiating end of hook
				var end = end_pos.instantiate()
				end.set_hook_properties(HOOK_POS)
				self.add_sibling(end)
			
	elif Input.is_action_just_released("HOOK") and hooked:
		hooked = false
		get_parent().get_node("HOOK").queue_free()

	if hooked:
		apply_central_force(ray_cast_2d.target_position * 10)

Any help at all will be appreciated, as i’ve been scratching my head over this for a good few hours now lol…

You might have to check if your directions and positions your are calculating your force from are all global. You should also check if the apply_central_force method applies the force locally or globally.