public void Launch(TargetPoint target) { Vector3 launchPoint = mortar.position; Vector3 targetPoint = target.Position; targetPoint.y = 0f; Vector2 dir; dir.x = targetPoint.x - launchPoint.x; dir.y = targetPoint.z - launchPoint.z; float x = dir.magnitude; float y = -launchPoint.y; dir /= x; float g = 9.81f; float s = launchSpeed; float s2 = s * s; float r = s2 * s2 - g * (g * x * x + 2f * y * s2); Debug.Assert(r >= 0f, "범위에 불충분 한 발사 속도!"); float tanTheta = (s2 + Mathf.Sqrt(r)) / (g * x); float cosTheta = Mathf.Cos(Mathf.Atan(tanTheta)); float sinTheta = cosTheta * tanTheta; mortar.localRotation = Quaternion.LookRotation(new Vector3(dir.x, tanTheta, dir.y)); //Vector3 prev = launchPoint, next; //for (int i = 1; i <= 10; i++) { // float t = i / 10f; // float dx = s * cosTheta * t; // float dy = s * sinTheta * t - 0.5f * g * t * t; // next = launchPoint + new Vector3(dir.x * dx, dy, dir.y * dx); // Debug.DrawLine(prev, next, Color.blue, 1f); // prev = next; //} //Debug.DrawLine(launchPoint, targetPoint, Color.yellow, 1f); //Debug.DrawLine( // new Vector3(launchPoint.x, 0.01f, launchPoint.z), // new Vector3(launchPoint.x + dir.x * x, 0.01f, launchPoint.z + dir.y * x), // Color.white, 1f //); Game.SpawnShell().Initialize( launchPoint, targetPoint, new Vector3(s * cosTheta * dir.x, s * sinTheta, s * cosTheta * dir.y), shellBlastRadius, shellDamage); }
public void Initialize(Vector3 position, float blastRadius, float damage = 0f) { if (damage > 0f) { TargetPoint.FillBuffer(position, blastRadius); for (int i = 0; i < TargetPoint.BufferedCount; i++) { TargetPoint.GetBuffered(i).Enemy.ApplyDamage(damage); } } transform.localPosition = position; scale = 2f * blastRadius; }
protected bool TrackTarget(ref TargetPoint target) { if (target == null || !target.Enemy.IsValidTarget) { return(false); } Vector3 a = transform.localPosition; Vector3 b = target.Position; float x = a.x - b.x; float z = a.z - b.z; float r = targetingRange + 0.125f * target.Enemy.Scale; if (x * x + z * z > r * r) { target = null; return(false); } return(true); }