Search Unity

TopDown Tank Movement AI

Discussion in 'Scripting' started by Cnc96, May 29, 2015.

  1. Cnc96

    Cnc96

    Joined:
    Dec 17, 2013
    Posts:
    57
    Hi all,
    I'm wandering if there is an easy way to make a NavMeshAgent stop moving and just rotate if the agent needs to turn to follow its path, as I'm looking for a way to try and get an arcade-like tank motion like that seen in the image below:


    I was thinking that I could perhaps use a combination of the steeringTarget, updatePosition and updateRotation to achieve this?
    Would that be the right way to approach the problem, or would I have to do something else?
     
  2. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
    Stop and temporarily disable the navMesh Agent script, then swith to a turning function and when done turning, enable the navmesh agent again.
     
  3. Cnc96

    Cnc96

    Joined:
    Dec 17, 2013
    Posts:
    57
    That seems like an incredibly inefficient thing to though as the script which assigns the target, has a number of variables it assigns on start up? So if I had a number of tank objects with this, that would eventually impact performance would it not?
     
  4. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
    You don't need to re-run your assigning script and you also don't have to completely disable the navmesh agent. You could just stop it and let your rotation script kick in for that moment. I can't see why it should give you any performance issues at all.
     
  5. OJDee

    OJDee

    Joined:
    Feb 11, 2014
    Posts:
    64
    Trying to achieve the same effect, tank rotates before moving in desired direction via navmesh agent. Something along these lines, if the tank is facing more than 10 degrees away from the desiredVelocity (from navmesh pathing), it can only rotate, then once facing almost in the right direction, it can move forward again.

    if (Vector3.Angle(transform.forward, agent.desiredVelocity) > 10) {
    agent.updatePosition = false;
    } else {
    agent.updatePosition = true;
    }

    This works quite well, but it can get hung up when moving around a sharp corner for example.. still needs some tuning to smooth out the kinks.

    Also, what game is that in the gif?

    NVM, found it: Last Invader
    http://www.kongregate.com/games/MrCatastropher/last-invader?acomplete=last+invader
     
    Last edited: Jul 21, 2015