Hello everyone and thanks for reading this So I made a script for horor AI and AI is teleporting randomly in the map. So the problem is when enemy teleports it can be teleport to the inside of objects. I mean I can see enemies body is half on the outside half is inside of the car. How I can fix this. Thanks and sorry for my english
var newPos = new Vector3(Random.Range(player.position.x + mesafe, player.position.x - mesafe), Random.Range(player.position.y, player.position.y), Random.Range(player.position.z + mesafe, player.position.z - mesafe));
// This will check to see if there is anything in the way before teleporting there.
if (!Physics.CheckCapsule(newPos - Vector3.up, newPos + Vector3.up, 0.5)) {
transform.position = newPos;
}else{
// Do something else. Maybe restart the teleport function to try again.
}
I suggest you read about Physics.CheckCapsule in the docs.