diff options
Diffstat (limited to 'Chicken.gd')
-rw-r--r-- | Chicken.gd | 34 |
1 files changed, 18 insertions, 16 deletions
@@ -2,6 +2,7 @@ extends KinematicBody export var rot_chance = 5.0 export var rot_range = PI / 4.0 +export var rot_speed = PI / 4.0 export var mov_chance = 5.0 export var mov_speed = 1.0 export var mov_length_min = 1.0 @@ -33,21 +34,22 @@ func _physics_process(delta): pass func state_idle(delta): - if roll_die(rot_chance): - 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()) - 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") + if !$SmoothRotation.is_active(): + if roll_die(rot_chance): + var ang = (randf() - 0.5) * rot_range + $SmoothRotation.rotate_y(ang, rot_speed) + elif 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()) + var mov = local_forward * dist + mov_velocity = mov.normalized() * mov_speed + mov_target = transform.origin + 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_velocity = Vector3.ZERO var mov_target = Vector3.ZERO @@ -61,7 +63,7 @@ func state_moving(_delta): var collision = get_slide_collision(index) if collision.collider.name == "Fence": mov_steps = 0.0 - look_at(translation + collision.normal ,Vector3.UP) + $SmoothRotation.rotate_y((-transform.basis.z.normalized()).signed_angle_to(collision.normal,Vector3.UP),rot_speed) mov_steps -= 1.0 if mov_steps < 1.0: mov_velocity *= mov_steps |