29 lines
569 B
GDScript3
29 lines
569 B
GDScript3
|
extends Spatial
|
||
|
|
||
|
|
||
|
var target := Vector3.ZERO
|
||
|
|
||
|
var acceleration := Vector3.ZERO
|
||
|
var velocity := Vector3.ZERO
|
||
|
|
||
|
export var acceleration_factor = 5.0
|
||
|
export var accelerating := false
|
||
|
|
||
|
|
||
|
func _ready():
|
||
|
$HitArea.connect("body_entered", self, "_on_hit_body")
|
||
|
|
||
|
|
||
|
func _on_hit_body(body):
|
||
|
if body.name == "Player":
|
||
|
print("Player hit!")
|
||
|
|
||
|
|
||
|
func _process(delta):
|
||
|
if accelerating:
|
||
|
var direction = (target - global_transform.origin).normalized()
|
||
|
acceleration += direction * acceleration_factor * delta
|
||
|
velocity += acceleration
|
||
|
|
||
|
global_transform.origin += velocity * delta
|