Example #1
0
    protected override void Shoot0()
    {
        TargetAble target = targets[0];
        Vector3    point  = target.GetPosition();

        turret.LookAt(point);
        laserBeam.localRotation = turret.localRotation;
        float d = Vector3.Distance(turret.position, point);

        laserBeamScale.z        = d;
        laserBeam.localScale    = laserBeamScale;
        laserBeam.localPosition =
            turret.localPosition + 0.5f * d * laserBeam.forward;
    }
Example #2
0
    public void Launch()
    {
        TargetAble target      = targets[0];
        Vector3    launchPoint = mortar.position;
        Vector3    targetPoint = target.GetPosition();

        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, "Launch velocity insufficient for range!");
        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));

        Game.SpawnShell().Initialize(
            launchPoint, targetPoint,
            new Vector3(s * cosTheta * dir.x, s * sinTheta, s * cosTheta * dir.y),
            shellBlastRadius, shellDamage
            );
    }