29 lines
693 B
GDScript
29 lines
693 B
GDScript
extends KinematicBody
|
|
|
|
|
|
var target := Vector3.ZERO
|
|
|
|
var acceleration := Vector3.ZERO
|
|
var velocity := Vector3.ZERO
|
|
|
|
export var acceleration_factor = 5.0
|
|
export var accelerating := false
|
|
|
|
export var coefficient_of_restitution := 0.5
|
|
|
|
|
|
func _physics_process(delta):
|
|
if accelerating:
|
|
var direction = (target - global_transform.origin).normalized()
|
|
acceleration += direction * acceleration_factor * delta
|
|
velocity += acceleration
|
|
|
|
var collision = move_and_collide(velocity * delta)
|
|
|
|
if collision:
|
|
var normal = collision.normal
|
|
velocity = coefficient_of_restitution * (velocity - 2 * velocity.dot(normal) * normal)
|
|
|
|
if collision.collider.name == "Player":
|
|
print("Player hit!")
|