eel waving animation capability
This commit is contained in:
parent
a8906f82f0
commit
5a73af8887
1 changed files with 23 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
extends "res://objects/enemy/enemy.gd"
|
||||
|
||||
|
||||
# distance between segments
|
||||
const SEGMENT_LENGTH: float = 4.0
|
||||
|
||||
|
@ -7,12 +8,17 @@ const SEGMENT_LENGTH: float = 4.0
|
|||
export var segments: int = 8
|
||||
# speed eel travels
|
||||
export var speed: float = 32.0
|
||||
# how far eel travels along path for complete wave
|
||||
export var wave_length: float = 0.0
|
||||
# intensity in pixels of eel wave animation
|
||||
export var wave_amplitude: float = 0.0
|
||||
|
||||
var _segments: Array
|
||||
|
||||
onready var head: PathFollow2D = $Head
|
||||
onready var tail: PathFollow2D = $Tail
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
# get nodes
|
||||
var first_segment: PathFollow2D = $Segment
|
||||
|
@ -36,11 +42,15 @@ func _ready() -> void:
|
|||
first_segment.queue_free()
|
||||
first_segment_shape.queue_free()
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# move along path
|
||||
head.offset += speed * delta
|
||||
# position segments accordingly
|
||||
_offset_segments()
|
||||
# waving animation
|
||||
_wave_segments()
|
||||
|
||||
|
||||
func _offset_segments() -> void:
|
||||
# put tail at end
|
||||
|
@ -50,6 +60,19 @@ func _offset_segments() -> void:
|
|||
# set segment position based on index and length
|
||||
_segments[i].offset = head.offset - SEGMENT_LENGTH * float(i + 1)
|
||||
|
||||
|
||||
func _wave_segments() -> void:
|
||||
# save the effort of looping if nothing will come of it
|
||||
if wave_length == 0.0 and wave_amplitude == 0.0:
|
||||
return
|
||||
for child in get_children():
|
||||
# only affect childent that are pathfollows
|
||||
var segment = child as PathFollow2D
|
||||
if segment:
|
||||
# multiply by tau to use pixels as unit
|
||||
segment.v_offset = sin(segment.offset * TAU / wave_length) * wave_amplitude
|
||||
|
||||
|
||||
func die() -> void:
|
||||
# instance death particles for every segment
|
||||
for segment in _segments:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue