void AdvanceHeatSeeking(float waveTime) { if (!Enemy.IsActive) { Utilities.Log(" enemy no longer active (projectile dead)"); IsComplete = true; Destroy(); return; } float hypotenuse = Vector3.Distance(Position, Enemy.Position); float distanceMovedThisFrame = (float)(waveTime - LastUpdateTime) * ProjectileType.AirSpeed; LastUpdateTime = waveTime; // If we hit the target, apply the effects (damage, slow, etc) if (distanceMovedThisFrame >= hypotenuse) { IsComplete = true; ProcessImpact(Enemy.Position, waveTime, Enemy); Destroy(); return; } #if LEVEL_EDITOR Vector3 direction = Enemy.Position - Position; direction = VectorHelpers.Normalize(direction); #else Vector3 direction = (Enemy.Position - Position).normalized; #endif Vector3 progress = direction * distanceMovedThisFrame; Position += progress; GameObjectFactory.SetMapPos(go, Position); #if LEVEL_EDITOR == false go.transform.forward = direction; #endif }
public void UpdatePosition(LevelDescription levelDesc) { if (ReachedFinishLine) { Destroy(); } else { int posIndex = (int)LinearProgress; MapPos newMapPos = null; Utilities.Assert(posIndex < levelDesc.Road.Count); newMapPos = levelDesc.Road[posIndex]; if (MapPosition != newMapPos) { if (null != MapPosition) { MapPosition.EnemiesOccupying.Remove(this); } newMapPos.EnemiesOccupying.Add(this); MapPosition = newMapPos; } float intraMapProgress = (LinearProgress - (float)posIndex); #if LEVEL_EDITOR float progressFromCenter = Math.Abs(0.5F - intraMapProgress); #else float progressFromCenter = Mathf.Abs(0.5F - intraMapProgress); #endif Vector3 direction; if ((intraMapProgress < 0.5F) && (posIndex > 0)) { direction = levelDesc.Road[posIndex - 1].Pos - levelDesc.Road[posIndex].Pos; #if LEVEL_EDITOR direction = VectorHelpers.Normalize(direction); #else direction = direction.normalized; #endif } else if ((intraMapProgress < 0.5F) && (posIndex == 0)) { // straight down direction = new Vector3(0.0F, 0.0F, -1.0F); } else if ((intraMapProgress >= 0.5F) && (posIndex == (levelDesc.Road.Count - 1))) { // straight up direction = new Vector3(0.0F, 0.0F, 1.0F); } else { direction = levelDesc.Road[posIndex + 1].Pos - levelDesc.Road[posIndex].Pos; #if LEVEL_EDITOR direction = VectorHelpers.Normalize(direction); #else direction = direction.normalized; #endif } Vector3 movement = direction * progressFromCenter; Vector3 newPosition = levelDesc.Road[posIndex].Pos + movement; Vector3 forward = newPosition - Position; #if LEVEL_EDITOR forward = VectorHelpers.Normalize(forward); forward.Z = -forward.Z; #else forward = forward.normalized; forward.z = -forward.z; #endif Position = newPosition; GameObjectFactory.SetMapPos(go, Position); #if !LEVEL_EDITOR go.transform.forward = forward; UpdateHealthIndicator(); #endif } }