phs-galaxy/Bullet.gd
2021-06-28 12:39:56 +02:00

22 lines
544 B
GDScript

extends KinematicBody
var target := Vector3.ZERO
var acceleration := Vector3.ZERO
var velocity := Vector3.ZERO
export var coefficient_of_restitution := 0.5
func _physics_process(delta):
var collision = move_and_collide(velocity * delta)
if collision:
# Reflect the bullet and decrease the velocity according to the coefficient of restitution
var normal = collision.normal
velocity = coefficient_of_restitution * (velocity - 2 * velocity.dot(normal) * normal)
if collision.collider.name == "Player":
print("Player hit!")