How do you repel objects away form a area2D when the objects are inside it?

Godot Version

4.2.2

Question

How do you repel objects away form a area? Example:

You could take the difference between the Area2D global_position and the obj global_position and move the object with the opposite vector.

A quick example:

extends Area2D


func _process(delta: float) -> void:
	for other_area in get_overlapping_areas():
		var diff = global_position - other_area.global_position
		other_area.global_position += -diff.normalized() * delta * 100.0

1 Like

Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.