How to pull character towards an object

Godot Version


Please explain what you’re looking for in more detail, what you have already tried etc.

1 Like

I need to pull the characterbody3D towards a static body3D. Best would be to make it happen in an area3D.

What have you tried, or what part are you struggling with? Generally you would:

  1. detect when body enters the area
  2. apply a force to it as long as its there
  3. detect when the body exits

Im struggling mostly with pulling the character in the correct direction

The Vector2 and Vector3 class have a method called “direction_to”.
You could try doing something like this:

var character_pos := player.global_position
var pulling_thing_pos := puller.global_position
var pulling_direction := character_pos.direction_to(pulling_thing_pos)

I found the method by searching in Godot’s documentation.
Vector2 — Godot Engine (stable) documentation in English (for Vector2 values)
Vector3 — Godot Engine (stable) documentation in English (for Vector3 values)