Patrolling character on NavMesh – ShiVa Engine

Patrolling character on NavMesh

This snippet makes a character move to random points, stop there and move again to other points while running animations. The camera focuses always on the character.
– Create a NavMesh in your Scene,
– Add a tag to your character, let’s say “MyCharacter”,
– Add that code to one of your User AIModels:

function MyMainAI.onEnterFrame ( )
    ...
    local x, y, z = object.getTranslation ( application.getCurrentUserActiveCamera ( ), object.kGlobalSpace )
    object.lookAt ( application.getCurrentUserSceneTaggedObject ( "MyCharacter" ), x, y, z, object.kGlobalSpace, 1 )
    ...
end
----------------------------------------------------------------------------------
--Add an AIModel to your character, let's say "MyCharacterAI", and add it an onEnterFrame script:
----------------------------------------------------------------------------------
function MyCharacterAI.onEnterFrame ( )
    local o = this.getObject ( )
    if ( object.hasController ( o, object.kControllerTypeNavigation )
    and  navigation.getNode   ( o ) )
    then
        if ( not navigation.getTargetNode ( o ) )
        then
            navigation.setRandomTargetNode ( o )
        end
    else
        navigation.setNearestNode ( o, o )
    end
end



Need more answers?

  • slackBanner