Quantcast
Channel: Latest Questions by khoatic
Viewing all articles
Browse latest Browse all 97

LOS Rotation with constant width

$
0
0
I have a basic scene right now with two objects, spheres just for now. One is going to be the AI while the other the player. Im trying to check if the AI is in LOS of the Player. If the AI is, im wanting him to go directly to the player. However in order to make sure its a smooth path without colliding Im using two raycasts to simulate the width the AI needs in order to not hit anything when going directly to the player. the problem is that when rotating these two rays its skewing the distance. Ideally what im wanting the ray cast as its rotating is like the picture i provided. Here is also the code im using now to do my LOS check. public bool isInLOS() { //this = AI ; safeLOSSpace = width of extra space Vector3 newPlayer1 = new Vector3(player.transform.position.x + safeLOSSpace, player.transform.position.y, player.transform.position.z); Vector3 newPos1 = new Vector3(this.gameObject.transform.position.x + safeLOSSpace, this.gameObject.transform.position.y, this.gameObject.transform.position.z); Vector3 newPlayer2 = new Vector3(player.transform.position.x - safeLOSSpace, player.transform.position.y, player.transform.position.z); Vector3 newPos2 = new Vector3(this.gameObject.transform.position.x - safeLOSSpace, this.gameObject.transform.position.y, this.gameObject.transform.position.z); Vector3 ray1 = newPlayer1 - newPos1; Vector3 ray2 = newPlayer2 - newPos2; RaycastHit hit; float dist = Vector3.Distance(player.transform.position, this.gameObject.transform.position); Debug.DrawRay(newPos1, ray1, Color.magenta); Debug.DrawRay(newPos2, ray2, Color.magenta); if (Physics.Raycast(newPos1, ray1, out hit, dist, LOSMask)) { Debug.Log(hit.collider.gameObject); if (hit.collider.gameObject == player) { pass1 = true; } else { return false; } } if (pass1) { if (Physics.Raycast(newPos2, ray2, out hit, dist, LOSMask)) { if (hit.collider.gameObject == player) { return true; } } } return false; } ![alt text][1] [1]: /storage/temp/26201-untitled-1.png

Viewing all articles
Browse latest Browse all 97

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>