[ad_1]
I’ve a ship that may shoot targets, however cannons on the precise facet ought to by no means attempt to shot at targets on the left facet of the ship. Thus I’ve created sectors utilizing the SignedAngle
perform, this works high-quality for testing, however its additionally sort of damaged as you may see from the visualization beneath.
I’ve tried utilizing boxcast
however alas it additionally doesnt work for this use case.
The above picture visualizes what my script does, however this isn’t an answer to my downside. As targets near the facet and entrance of the ship will likely be exterior the sector, for clarification what I imply, see image 3.
This second picture exhibits what occurs after we enhance the angle, we are able to now detect extra targets, however now we have 2 massive incorrect sectors marked in crimson which shouldnt be there.
Finally, that is how I believe it ought to look, its nonetheless a cone, however the massive distinction is that it begins with a large backside, thus it resolves the issue Im having with the present SignedAngle perform which determines every little thing from a single level within the center.
This is the script for assigning targets to the right record based on which sector they’re in:
foreach (Transform 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.Contains(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.Contains(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.Contains(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.Contains(goal))
{
RemoveFromOthers(goal);
psTargets.Add(goal);
print("added goal to PS");
}
}
}
Any assist could be appreciated on easy methods to deal with this downside!
Thank you.
[ad_2]