From fe334f8d1560833ee5eab58c94182addc248041a Mon Sep 17 00:00:00 2001 From: Jason Durand 01 Date: Sat, 2 Apr 2022 11:02:29 -0400 Subject: [PATCH] Added Entity.beingPushed() state without actually using it --- Assets/Scripts/Entity.cs | 14 +++++++++++--- Assets/Scripts/Monster.cs | 6 +++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index 77a143b..891e2af 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -30,6 +30,14 @@ public class Entity : MonoBehaviour attackTimer = attackCooldown; } + protected virtual void FixedUpdate() { + //TODO sqrMagnitude? + if (beingPushed && rb.velocity.magnitude < stats.MinVelocityWhenPushed) { + rb.velocity = Vector2.zero; + beingPushed = false; + } + } + protected virtual void Attack(){ // jason: TODO Either have target be Entity instead of transform, or skip Attack when GetComponent() is null Entity targetEntity = target.GetComponent(); @@ -40,11 +48,11 @@ public class Entity : MonoBehaviour } - protected virtual void MoveToTarget(float deltaTime){ + protected virtual void MoveToTarget(){ - direction = Vector3.RotateTowards(direction, (target.position - transform.position), rotSpeed*deltaTime, 0.0f); + direction = Vector3.RotateTowards(direction, (target.position - transform.position), rotSpeed*Time.fixedDeltaTime, 0.0f); if(!IsInAttackRange()){ - rb.MovePosition(transform.position + direction * movementSpeed * deltaTime); + rb.MovePosition(transform.position + direction * movementSpeed * Time.fixedDeltaTime); } } diff --git a/Assets/Scripts/Monster.cs b/Assets/Scripts/Monster.cs index 77bd059..51e4937 100644 --- a/Assets/Scripts/Monster.cs +++ b/Assets/Scripts/Monster.cs @@ -11,7 +11,11 @@ public class Monster : Entity base.SetName("Monster"); } - void FixedUpdate() => MoveToTarget(Time.fixedDeltaTime); + protected override void FixedUpdate() { + base.FixedUpdate(); + + MoveToTarget(); + } // Update is called once per frame void Update()