ım tryna make a underwater game that shark chase us patrol and attack etc but shark is only act move like humanoid in the whole space i want it to move freely everywhere in the air (so in the water) what should ı do how to make it
Not enough info to really help, but ill try. For a fish (shark) to (attack, swim, patrol, etc.), it has to have an offset from the base NavMesh, meaning, its set height from the NavMesh.
I deal with this in my games every day. What i do is make sure my NavMesh is baked correctly, then set the offset/height of the fish, so hes basicly in the middle of the water (height-wise). Now set your waypoints or patrol radius, and everything should be good.
Now, please remember if your NavMesh isnt baked correctly, you will run into problems.
Remember that using the NavMesh binds you to the floor in some capacity. You can do as @warthos3399 said and adjust the height offset, and maybe even animate / adjust that value to change where the shark appears to be in 3d space even though the Shark is still technically on the floor. This is kind of a hacky solution and you will not get the free movement results that you would expect from a Shark. I would generally recommend for this kind of movement to position them in worldspace based on raycasting instead of using the NavMesh because the NavMesh is really for relatively planar movement, not fully 3d movement.
I also have a video about how to make “flying” NavMeshAgents if the short answers here were not enough.
thank you guys for your all answers really appreciate it but i needed to give up on this project maybe try later but shark aı really too far hard for me ,i couldnt solved it and waste lots of time without making nothing .so gave up but imporing myself on this AI topic i’ll making another project and now understand better. THNX GUYSS
I’ve followed your tutorial which is excellent, and am now trying to get my flying navmesh agent to patrol between 3 Waypoints. Agent does not change Y axis (up/down) unless there is an obstacle to ‘jump’ over. How can I have my flying agents respect the Y axis and go ‘up’ directly to my next Waypoint? I need code to change the agent’s vertical Y offset towards a waypoint. I want to keep NavMesh for obstacle avoidance, once I have defied gravity.
I can use waypoints + slerp code to get there, but then will be crashing into terrain and objects, it will be hard to find a path with raycasting.
Thank you .
It’s a little hard to understand the scenario without being able to see your scene, but I’ll assume you have something similar to the video with multi-elevation. For those you need NavMeshLinks to allow your flying agent to “walk” up the elevation. Based on the BaseOffset of the NavMeshAgent they will always be a relatively consistent height above the ground.
If you have a relatively flat level without multiple levels the Agent should be able to “step up”, and you are defining the waypoints in 3d, you can choose a location on the NavMesh to set the Agent’s destination and lerp the BaseOffset value from the current point to the Y component of the next waypoint. That way they will both travel on the NavMesh to the desired X/Z point and be lerped vertically to the target Y point.