phs-galaxy/Bullet.gd

29 lines
693 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
export var acceleration_factor = 5.0
export var accelerating := false
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):
if accelerating:
var direction = (target - global_transform.origin).normalized()
acceleration += direction * acceleration_factor * delta
velocity += acceleration
2021-06-07 19:20:38 +02:00
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!")