phs-galaxy/Bullet.gd
karl 219c8731f5 Add shooting enemy which shoots at future player pos
Works fairly well, although it doesn't account for changing acceleration which happens due to the changing gravity. I guess this is good enough, since it does hit if the player isn't careful
2021-06-07 16:41:56 +02:00

29 lines
569 B
GDScript

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