summaryrefslogtreecommitdiffstats
path: root/Chicken.gd
diff options
context:
space:
mode:
authordusoleil <howcansocksbereal@gmail.com>2022-07-23 10:56:12 -0400
committerdusoleil <howcansocksbereal@gmail.com>2022-07-23 10:56:12 -0400
commite79aa18fd2e808b1818552f22ce575799106a20c (patch)
treee8125433ac9ab7cb64f1929a50c587d46a715f1f /Chicken.gd
parent6ca263254e09ad74f4620394f4e170c3bea98f99 (diff)
downloadchicken-chaser-gd-e79aa18fd2e808b1818552f22ce575799106a20c.tar.gz
chicken-chaser-gd-e79aa18fd2e808b1818552f22ce575799106a20c.zip
Clean up Chicken movement
Diffstat (limited to 'Chicken.gd')
-rw-r--r--Chicken.gd39
1 files changed, 21 insertions, 18 deletions
diff --git a/Chicken.gd b/Chicken.gd
index 996c2eb..b9fb9a4 100644
--- a/Chicken.gd
+++ b/Chicken.gd
@@ -7,7 +7,7 @@ export var mov_speed = 1.0
export var mov_length_min = 1.0
export var mov_length_max = 5.0
export var flap_chance = 5.0
-export var squak_chance = 5.0
+export var squack_chance = 5.0
export var peck_chance = 5.0
onready var anim = $AnimationTree
@@ -34,31 +34,34 @@ func _physics_process(delta):
func state_idle(delta):
if roll_die(rot_chance):
- var ang = randf() * rot_range
+ var ang = (randf() - 0.5) * rot_range
rotate(Vector3.UP, ang)
if roll_die(mov_chance):
anim.state.travel("MOVING")
+ var local_forward = -transform.basis.z.normalized()
var dist = lerp(mov_length_min, mov_length_max, randf())
- mov_lerp_pos = 0.0
- mov_lerp_step = (mov_speed * delta) / dist
- var rotation = Transform(self.rotation, Vector3.ZERO)
- var forward = rotation * Vector3.FORWARD
- mov_lerp_start = translation
- mov_lerp_target = translation + (forward * dist)
- elif roll_die(squak_chance):
+ var mov = local_forward * dist
+ mov_velocity = mov.normalized() * mov_speed
+ mov_target = translation + mov
+ mov_steps = (dist / mov_speed) / delta
+ elif roll_die(squack_chance):
anim.state.travel("SQUACK")
elif roll_die(peck_chance):
anim.state.travel("PECK")
-var mov_lerp_start = Vector3.ZERO
-var mov_lerp_target = Vector3.ZERO
-var mov_lerp_step = 0.0
-var mov_lerp_pos = 0.0
+var mov_velocity = Vector3.ZERO
+var mov_target = Vector3.ZERO
+var mov_steps = 0.0
func state_moving(_delta):
- if mov_lerp_pos >= 1.0:
+ if mov_steps <= 0.0:
anim.state.travel("IDLE")
return
- mov_lerp_pos += mov_lerp_step
- mov_lerp_pos = min(mov_lerp_pos, 1.0)
- var pos = lerp(mov_lerp_start, mov_lerp_target, mov_lerp_pos)
- pos = move_and_slide(pos - translation, Vector3.UP)
+ var vmp = move_and_slide(mov_velocity, Vector3.UP)
+ for index in range(get_slide_count()):
+ var collision = get_slide_collision(index)
+ if collision.collider.name == "Fence":
+ mov_steps = 0.0
+ look_at(translation + collision.normal ,Vector3.UP)
+ mov_steps -= 1.0
+ if mov_steps < 1.0:
+ mov_velocity *= mov_steps