phs-galaxy/Bullet.gd

22 lines
544 B
GDScript3
Raw Normal View History

2021-06-07 19:20:38 +02:00
extends KinematicBody
var target := Vector3.ZERO
var acceleration := Vector3.ZERO
var velocity := Vector3.ZERO
2021-06-07 19:20:38 +02:00
export var coefficient_of_restitution := 0.5
2021-06-07 19:20:38 +02:00
func _physics_process(delta):
var collision = move_and_collide(velocity * delta)
if collision:
2021-06-28 12:39:56 +02:00
# Reflect the bullet and decrease the velocity according to the coefficient of restitution
2021-06-07 19:20:38 +02:00
var normal = collision.normal
velocity = coefficient_of_restitution * (velocity - 2 * velocity.dot(normal) * normal)
if collision.collider.name == "Player":
print("Player hit!")