EntityNavWalker entity[,enabled]

Parameters

entity - the entity

enabled (optional) - True makes it a NavWalker (default); False takes it out of the crowd

Description

Makes an entity a NavWalker that stands where it is, or takes it out of the crowd.

A NavWalker is any entity the engine walks: WalkEntity, FollowEntity, WanderEntity and the walker settings (WalkSpeed and the rest) all make one. EntityNavWalker makes one with nowhere to go. It stands, other walkers step round it, it can be pushed, and it is ready for its first order: a shopkeeper behind a stall, a sentry at a gate, a crowd waiting for the show. On an entity that already is a NavWalker it does nothing, even if the walker is on its way somewhere.

EntityNavWalker entity,False hands the entity back to the program, or to physics. The crowd stops moving, turning and animating it, other walkers stop stepping round it, and CountNavWalkers no longer counts it. It stays where it is. Use it when something else takes over: a ragdoll, a cutscene, or a character the player picks up. WalkEntity or EntityNavWalker later makes it a NavWalker again, put on the map where it is then.

Gotcha: leaving forgets everything the crowd knew about the entity: its goal, and what WalkSpeed, WalkTurnSpeed, WalkSize, WalkAreaCost, WalkRegion, WalkAvoidance, WalkAnimations and WalkPushable gave it. Set them again when it comes back. It also comes back last in the order of GetNavWalker.

Whatever it is made of, a walker is never part of the walkable map it walks on: EntityNavigationChoice says "not in the map (it walks)". FreeEntity takes a walker out of the crowd too.

See also: WalkEntity, StopWalking, CountNavWalkers, NavWalkersAvoid, EntityNavigation.

Example

; EntityNavWalker Example
; -----------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

; A raised camera looking down on the square
camera=CreateCamera()
PositionEntity camera,0,13,-12
RotateEntity camera,50,0,0

light=CreateLight()
RotateEntity light,45,45,0

; A 20 x 20 m square, one unit to a metre: the floor's top is at y=0
floor=Block(0,-0.5,0,20,0.5,20)
EntityColor floor,60,80,55

; Three people standing in a row across the square. As NavWalkers with
; nowhere to go, they stand, and walkers step round them.
For i=-1 To 1
    person=Character(i*3,0,90,140,220)
    EntityNavWalker person
    If i=0 Then juggler=person
Next

; A messenger who runs to and fro through the row
messenger=Character(0,-8,220,60,60)
goal_z#=8
WalkEntity messenger,0,0,goal_z,True
in_crowd=True
hop#=0

While Not KeyDown(1)

    ; Space takes the middle person out of the crowd, to juggle on the spot,
    ; or puts them back
    If KeyHit(57) Then
        in_crowd=Not in_crowd
        If in_crowd Then
            PositionEntity juggler,0,0.9,0
            EntityNavWalker juggler
        Else
            EntityNavWalker juggler,False
        EndIf
    EndIf

    ; Out of the crowd, the juggler is the program's: it hops and spins
    If Not in_crowd Then
        hop=hop+6
        PositionEntity juggler,0,0.9+Abs(Sin(hop))*0.6,0
        TurnEntity juggler,0,4,0
    EndIf

    ; At one end, the messenger turns back for the other
    If WalkState(messenger)=WALK_ARRIVED Then
        goal_z=-goal_z
        WalkEntity messenger,0,0,goal_z,True
    EndIf

    ; Arrow keys move the camera (turning round the world's up axis)
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0,True
    If KeyDown(205) Then TurnEntity camera,0,-1,0,True

    UpdateWorld
    RenderWorld

    Text 0,0,"Space: middle person in / out of the crowd   Arrow keys: camera   Esc: exit"
    If in_crowd Then
        Text 0,20,"EntityNavWalker juggler: standing, and the messenger runs round"
    Else
        Text 0,20,"EntityNavWalker juggler,False: the program's, and nobody steps round"
    EndIf
    Text 0,40,"NavWalkers in the square: "+CountNavWalkers()

    Flip

Wend

End

; A stone block standing on y, centred on x,z
Function Block(x#,y#,z#,width#,height#,depth#)
    b=CreateCube()
    ScaleEntity b,width/2,height/2,depth/2
    PositionEntity b,x,y+height/2,z
    EntityColor b,125,110,90
    Return b
End Function

; A character 0.6 m across and 1.8 m tall, with a visor on its face, kept out
; of the walkable map it walks on
Function Character(x#,z#,red,green,blue)
    c=CreateCube()
    ScaleMesh c,0.3,0.9,0.3
    PositionEntity c,x,0.9,z
    EntityColor c,red,green,blue
    visor=CreateCube(c)
    ScaleMesh visor,0.2,0.08,0.06
    PositionEntity visor,0,0.6,0.32
    EntityColor visor,30,30,40
    Return c
End Function

Index