-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRepulsionArea.gd
More file actions
31 lines (22 loc) · 851 Bytes
/
RepulsionArea.gd
File metadata and controls
31 lines (22 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
extends Area
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
export var radius : float
export var max_repulsion : float
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
var bodies = get_overlapping_bodies()
print(bodies)
for body in bodies:
var distance_vector : Vector3 = (self as Spatial).global_transform.origin - (body as Spatial).global_transform.origin
var direction = distance_vector.normalized()
var magnitude = distance_vector.length()
var repulsion_factor = (radius - magnitude) / radius
var impulse = direction * max_repulsion * repulsion_factor
#print(force)
(body as RigidBody).apply_central_impulse(impulse)
pass