Skip to content

Commit

Permalink
Update MissileScript.cs
Browse files Browse the repository at this point in the history
Fixed missiles not getting destroyed when reaching their target if the target was already destroyed
  • Loading branch information
MatthewGB authored Jul 23, 2020
1 parent c3d517f commit 9ad1d0b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Assets/Scripts/Abilities/MissileScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,19 @@ public void SetTarget(Transform target)
}

// Update is called once per frame
void FixedUpdate () {
void FixedUpdate ()
{
if(target && (!target.GetComponent<Entity>() || !target.GetComponent<Entity>().invisible))
{
var moveVector = (target.position - transform.position).normalized;
GetComponent<Rigidbody2D>().AddForce(120 * moveVector);
}
}

if (target && target.GetComponent<Entity>().GetIsDead() && Vector3.Distance(transform.position, target.position) < 0.1f)
{
Destroy(gameObject);
}
}

public void SetTerrain(Entity.TerrainType terrain)
{
Expand Down

0 comments on commit 9ad1d0b

Please sign in to comment.