From 343cf5bc3abb6e3fceb0bbae4ecf4322c2920424 Mon Sep 17 00:00:00 2001 From: Jens Pitkanen Date: Mon, 19 Aug 2019 00:55:47 +0300 Subject: [PATCH] Add flipping to mobcats --- Assets/Prefabs/Enemies/Enemy (MobCat).prefab | 1 + Assets/Scripts/Enemies/MobCat.cs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Assets/Prefabs/Enemies/Enemy (MobCat).prefab b/Assets/Prefabs/Enemies/Enemy (MobCat).prefab index 6b8762e..5d8d317 100644 --- a/Assets/Prefabs/Enemies/Enemy (MobCat).prefab +++ b/Assets/Prefabs/Enemies/Enemy (MobCat).prefab @@ -447,6 +447,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: Anim: {fileID: 5842195514978149329} + SpriteRenderer: {fileID: 4848125059538075066} --- !u!1 &3991584792453052187 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Enemies/MobCat.cs b/Assets/Scripts/Enemies/MobCat.cs index 09da6b1..2f494e5 100644 --- a/Assets/Scripts/Enemies/MobCat.cs +++ b/Assets/Scripts/Enemies/MobCat.cs @@ -12,6 +12,7 @@ namespace Saltosion.OneWeapon.Enemies { [RequireComponent(typeof(RangedAttackFollowed))] public class MobCat : MonoBehaviour { public Animator Anim; + public SpriteRenderer SpriteRenderer; private Enemy Enemy; private PlayerSighted FollowTrigger; @@ -47,6 +48,11 @@ namespace Saltosion.OneWeapon.Enemies { Anim.Play("Walk"); } Anim.SetFloat("Speed", Enemy.Movement.SpeedPercentage); + if (Enemy.Movement.SpeedPercentage > 0.1) { + SpriteRenderer.flipX = Vector2.Dot(Enemy.Movement.Direction, Vector2.left) < 0; + } else { + SpriteRenderer.flipX = Vector2.Dot(FollowBehaviour.TargetDirection, Vector2.left) < 0; + } } } }