4
I need to create an obstacle clearance script but I can’t use Navmeshagent because this project depends on implementations where the Navmeshagent doesn’t work.
See that in the image below there are two cubes and an obstacle, the blue cube represents the player while the red cube represents the enemy. The red cube has a Raycast that identifies whether the blue cube is near (red line), and then moves in the direction of the blue cube using a Vector3.forward
and LookAt
, but if there is any obstacle in front of the red cube the locomotion must be modified so that there is a deviation.
The problem is that I’m thinking if the best method to avoid the obstacle would be to take the size of the object in front and calculate the distance from its center to its edge + the size of the red cube to direct the red cube there and then continue its locomotion to the cube blue. Or shoot a rotating Raycast that will take the shortest free path and add up the position. But how to do this?
What would be the right way to make this detour? remembering that I cannot use the Navmeshagent in no case.
Pathfinding without navmesh in a free environment is complicated... You may not even use the native Unity, but Navmesh is very good for this type of situation. What you quoted is a "donkey" method, it would work well with an obstacle, but it would be horrific if the environment were more complex, and it certainly could get stuck in a "U" if it found a dead end.
– DH.
The problem is that Unity’s Navmesh only works with terrains, and I need to create this script for navigating on a sphere.
– Rafael Alexandre
Ah, if you’re going to pathfinding a planet or something like that then your best way out is an A* star itself or a derivative of it. http://gamedev.stackexchange.com/questions/53866/pathfinding-on-a-uneven-planetary-surface
– DH.
Well, first of all if your problem is with a sphere, make that clear in the question. If possible, also provide an example project so that someone can help you without having the trouble to create everything from scratch. The link that the colleague @DH. mentions is the best question related to what you need. There is this other on the Soen, whose only answer provides some interesting details (tutorial for you to create an A* in Unity3d, and even a link to Asset Store with a project that already does what you need).
– Luiz Vieira