Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How To Create navmesh for shark like flying moving

Discussion in 'Navigation' started by y20dincel, Aug 28, 2022.

  1. y20dincel

    y20dincel

    Joined:
    Jun 13, 2022
    Posts:
    2
    ı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 Screenshot_3.png
     
  2. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,650
    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.
     
  3. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    265
    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.
     
    Shamantiks and warthos3399 like this.
  4. y20dincel

    y20dincel

    Joined:
    Jun 13, 2022
    Posts:
    2
    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
     
    Shamantiks likes this.
  5. Shamantiks

    Shamantiks

    Joined:
    Mar 11, 2022
    Posts:
    10
    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.
     
  6. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    265
    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.