Minor code cleanup
This commit is contained in:
parent
7a96f549ff
commit
24ccf0ddbe
@ -6,21 +6,14 @@ var target := Vector3.ZERO
|
|||||||
var acceleration := Vector3.ZERO
|
var acceleration := Vector3.ZERO
|
||||||
var velocity := Vector3.ZERO
|
var velocity := Vector3.ZERO
|
||||||
|
|
||||||
export var acceleration_factor = 5.0
|
|
||||||
export var accelerating := false
|
|
||||||
|
|
||||||
export var coefficient_of_restitution := 0.5
|
export var coefficient_of_restitution := 0.5
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
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)
|
var collision = move_and_collide(velocity * delta)
|
||||||
|
|
||||||
if collision:
|
if collision:
|
||||||
|
# Reflect the bullet and decrease the velocity according to the coefficient of restitution
|
||||||
var normal = collision.normal
|
var normal = collision.normal
|
||||||
velocity = coefficient_of_restitution * (velocity - 2 * velocity.dot(normal) * normal)
|
velocity = coefficient_of_restitution * (velocity - 2 * velocity.dot(normal) * normal)
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ func _ready():
|
|||||||
_set_velocity_to_fly_towards_next_target()
|
_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`.
|
# so that the target will be reached after `target_fly_time`.
|
||||||
func _set_velocity_to_fly_towards_next_target():
|
func _set_velocity_to_fly_towards_next_target():
|
||||||
current_target_index = (current_target_index + 1) % target_paths.size()
|
current_target_index = (current_target_index + 1) % target_paths.size()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user