Search Unity

I want a NPC to jump from rooftop to rooftop primarily while patrolling, can anyone offer advice?

Discussion in 'Navigation' started by Apposl, Dec 9, 2017.

  1. Apposl

    Apposl

    Joined:
    Nov 27, 2017
    Posts:
    50
    I'm not sure exactly how to make this happen in the slightest way and just a little guidance in the right direction would be appreciated as far as what topic to look into. Is this a pathfinding issue? Does the rooftop/platform bit cause any extra difficulties I should be aware of? Is there an AI asset that might cover this nicely for me? Thank you for anything!
     
  2. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    708
    Although im not sure of the "right" way to do this...
    You could add a simple plane that connects roof tops set it as navmesh static make it a roofjump layer. Bake your navmesh and then remove the planes or set them as inactive so you can rebake later if needed.

    Now you just need to add a trigger at the edges and maybe do checks of the navmesh layer to play the correct animations(this would be the tricky part to look good)...

    So OnTriggerEnter agent.setBool("jumpStart", true);
    Transition to jumping
    When agent hits next other building trigger setbool "landing"...

    Hope that helps
     
    Last edited: Dec 9, 2017
    Apposl likes this.
  3. Apposl

    Apposl

    Joined:
    Nov 27, 2017
    Posts:
    50
    It does, thank you! I'm new to all this so sometimes I just have difficulty figuring out what terms or area to look at, and that helps a lot - and I like solutions like that, it might not be the "best/right" but I understand it, and I learn building it. Thank you!
     
  4. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    For general navigation you probably want to use the nav mesh that is built into unity. (even though there are other options, but they are a lot harder)

    The gaps between buildings can be bridged using those nav mesh connections. (or nav mesh links, not sure what they are called)

    You will have to handle the matching event when a navagent hits the connection (that's where you have to manually take over in your script and move the unit smoothly and play a jump animation).

    Finding the complete path should be left to the nav mesh. If the links are set, it will find the path and navigate it for you (calling the methods I talked about when a link is to be traversed).

    That's how I would do it.
    There are an unlimied number of ways you can do this of course, you don't even have to use the nav mesh, but it will be significantly more complicated then :p
     
    Apposl likes this.
  5. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    Forgot to add:
    If you want correct "jump start" and "jump land" animations as well, you need to invest more time though. It's all possible using the animator component, you can set targets for this purpose (there's even a official video tutorial about that somewhere on the website)
     
    Apposl likes this.
  6. Apposl

    Apposl

    Joined:
    Nov 27, 2017
    Posts:
    50
    Thank you so much! I planned on it being quite the task to learn, but I'm retired, it's fun, and your comments help me put together a picture of "what" I'm actually doing and the pieces I need to learn. Thank you!
     
  7. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    This is a little late but I thought I would add to this in case others find it.

    I would use the navmeshlink instead of placing a temporary object and baking it to connect the two roofs.

    The reason is ( and I've made this mistake). Is that if you have multiple navmeshagents trying to cross at the same time, the navmeshlink will prevent them from traversing it at the same time (causing overlap of characters)...something that a trigger and animation cannot do by themselves.
     
    JBR-games likes this.
  8. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I have npc's that jump, and the simplest solution is really to just pick a valid point to jump to using appropriate logic, like having a list of rooftops within range or a list of specific jump points, and then just use Navmesh.SamplePosition to ensure it's on the navmesh, and then just do your jump. Offmesh links just complicate this IMO.
     
  9. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    510
    NavmeshLinks are more complicated, that's why I said if you have multiple agents then use it to prevent overlap of agents.