Saturday, September 17, 2022
HomeGame Developmentunity - Decide which cannons on a ship can hit a goal

unity – Decide which cannons on a ship can hit a goal


I’ve a ship that can shoot targets, however cannons on the fitting aspect ought to by no means attempt to shot at targets on the left aspect of the ship. Thus I’ve created sectors utilizing the SignedAngle perform, this works high quality for testing, however its additionally form of damaged as you possibly can see from the visualization beneath.
I’ve tried utilizing boxcast however alas it additionally doesnt work for this use case.

img1

The above picture visualizes what my script does, however this isn’t an answer to my downside. As targets near the aspect and entrance of the ship will likely be outdoors the sector, for clarification what I imply, see image 3.
img2

This second picture exhibits what occurs after we improve the angle, we will now detect extra targets, however now we have 2 huge incorrect sectors marked in purple which shouldnt be there.
img3 Correct

Lastly, that is how I feel it ought to look, its nonetheless a cone, however the huge distinction is that it begins with a large backside, thus it resolves the issue Im having with the present SignedAngle perform which determines all the pieces from a single level within the center.

That is the script for assigning targets to the right record in response to which sector they’re in:

foreach (Rework goal in EnemyListManager.occasion.enemyShips.ToArray())
        {

            if (Vector3.Distance(remodel.place, goal.place) > ship.mainGunCaliber.vary)
                proceed;

            Vector3 toTarget = goal.place - remodel.place;
            print(Vector3.SignedAngle(hullParent.ahead, toTarget, Vector3.up));

            if (Vector3.SignedAngle(hullParent.ahead, toTarget, Vector3.up) >= bowMinAngle &&
                Vector3.SignedAngle(hullParent.ahead, toTarget, Vector3.up) <= bowMaxAngle)
            {
                if (!bowTargets.Comprises(goal))
                {
                    RemoveFromOthers(goal);
                    bowTargets.Add(goal);
                    print("added goal to Bow");
                }
                proceed;
            }
            if (Vector3.SignedAngle(hullParent.ahead, toTarget, Vector3.up) >= sbMinAngle &&
                Vector3.SignedAngle(hullParent.ahead, toTarget, Vector3.up) <= sbMaxAngle)
            {
                if (!sbTargets.Comprises(goal))
                {
                    RemoveFromOthers(goal);
                    sbTargets.Add(goal);
                    print("added goal to SB");

                }
                proceed;

            }
            if (Vector3.SignedAngle(-hullParent.ahead, toTarget, Vector3.up) >= aftMinAngle &&
                Vector3.SignedAngle(-hullParent.ahead, toTarget, Vector3.up) <= aftMaxAngle)
            {
                if (!aftTargets.Comprises(goal))
                {
                    RemoveFromOthers(goal);
                    aftTargets.Add(goal);
                    print("added goal to Aft");

                }
                proceed;
            }
            if (Vector3.SignedAngle(hullParent.ahead, toTarget, Vector3.up) >= psMinAngle &&
                Vector3.SignedAngle(hullParent.ahead, toTarget, Vector3.up) <= psMaxAngle)
            {
                if (!psTargets.Comprises(goal))
                {
                    RemoveFromOthers(goal);
                    psTargets.Add(goal);
                    print("added goal to PS");

                }

            }
        }

Any assist could be appreciated on how you can sort out this downside!

Thanks.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments