One thing is that given grid cell occupation by a unit is irrelevant, the origin point (the player unit throwing the grenade) is also considered a valid target point. This leads to an error message in the console:
transform.position assign attempt for 'GrenadeProjectile(Clone)' is not valid. Input position is { 4,000000, NaN, 12,000000 }.
UnityEngine.Transform:set_position (UnityEngine.Vector3)
GrenadeProjectile:Update () (at Assets/Scripts/GrenadeProjectile.cs:42)
… so the calculated positionY
is NaN
.
The fix is an easy little trick:
In the GrenadeProjectile
's Setup()
do this:
totalDistance = Vector3.Distance(_positionXZ, _targetPosition) + 0.01f;
Adding a minimal value to the distance prevents it from being zero, and the error message is gone.
And I found that if the throwing player unit dies, control isn’t properly transfered over to the other unit.
This actually only happens when the selected player unit has died in the enemy turn when the OnTurnChanged
event is handled (since I changed my logic to fire on that signal because I had bugs when it was done on the OnAnyUnitDead
signal).
So I guess I would have to get back to using OnAnyUnitDead
again and make sure the older bug doesn’t reappear…