- Home /
SphereCastAll - Getting data out of "Order By"+ "ToArray"
So before I get to the question , first the set up:
Before I call this function, I have written another function that randomly selects a target. Once that is done a new function locks on the selected target using Look At.
Within this function the originpoint moves along a fixed path (looped) while a SphereCastAll is aimed at the target, to find a suitable position to hit the target.
As the "hit" condition can only be set to true, if there is a direct line with the opposing target, ... or better said 1 or less "friendly's" before it hits the target ... I've written this code to get a list of inbetween targets in an ordered Array:
RaycastHit[] directions = Physics.SphereCastAll(_originPoint, _sphereCastRadius, _direction, _spherecastMagnitude, layerMask).OrderBy(h => h.distance).ToArray();
What I want to do (logically) is:
If (the first hit along the spherecast == tag"Enemy" && The 2nd hit along the spherecast == tag"Enemy") { Keep Moving /do nothing } else if (the first hit along the spherecast == tag"Enemy" && The 2nd hit along the spherecast == tag"Player" { enable "hit" }
... and unless I am very much mistaken , the above code does sort the "hit"objects based on distance (from close to far from the origin point) and should put them in an Array...
But quite honestly I don't know how to get this data from the Raycast .. and after two days mucking about it is getting a bit ridiculous , so if anyone can shine a light on this, then that would be awesome!
Thanks in advance!
Martin
Your answer
Follow this Question
Related Questions
Vuforia enabled scripting define 0 Answers
scripting problem 0 Answers
Sorting a list based of a variable 1 Answer
Trying to change character skins at the push of a button. C# 1 Answer