Minor code cleanup

This commit is contained in:
karl 2021-06-28 12:39:56 +02:00
parent 7a96f549ff
commit 24ccf0ddbe
2 changed files with 2 additions and 9 deletions

View File

@ -6,21 +6,14 @@ 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:
# 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)

View File

@ -32,7 +32,7 @@ func _ready():
_set_velocity_to_fly_towards_next_target()
# Picks the next target position from the `target_paths` list and set the `velocity` appropriately
# Picks the next target position from the `target_paths` list and sets the `velocity` appropriately
# so that the target will be reached after `target_fly_time`.
func _set_velocity_to_fly_towards_next_target():
current_target_index = (current_target_index + 1) % target_paths.size()