|
entity - the walker enabled - True to let pushes move it, as every walker starts; False for a walker nothing pushes |
|
Chooses whether a walker can be pushed. Walkers push and are pushed by their weight, which is their EntityMass. A walker without one weighs 70 kg if it is the size of a person, and in proportion to its volume if it is bigger or smaller. A walker is pushed by: the player, or anything else NavWalkersAvoid marks, walking into it a Collisions source that runs into it, when the walker is the destination: by the part of its move the walker stopped a physics body that hits it other walkers still touching it in a crush, such as in a doorway EntityImpulse and EntityForce, which change its velocity by the push over its weight Each push is shared out by the two weights, so a big man shoves a child aside and the child barely moves him. A push carries the walker along and fades over half a second, while the walker steers on from wherever it has got to. A push faster than it can run stops it steering until it slows, and plays stagger if its animation set has one; pushed hard against an edge with ground below, it falls. WalkPushable entity,False makes a walker that nothing pushes, such as a guard holding a doorway or a bouncer at the club: in a crush, the others give way to it. It still pushes things by its weight, as when it walks into a crate (no harder than its weight times its acceleration). If the entity isn't a NavWalker yet, WalkPushable makes it one, standing where it is. Gotcha: a push moves the walker, but nothing stops the player walking through it unless the player collides with it. Give both an EntityType and a Collisions rule, as the example does, and the player bumps into the walker, which then gives way or holds firm. See also: NavWalkersAvoid, WalkAvoidance, WalkSpeed, EntityMass, EntityImpulse. |
; WalkPushable Example
; --------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
; The camera stays put above the yard: the arrow keys steer the player
camera=CreateCamera()
PositionEntity camera,0,13,-12
RotateEntity camera,50,0,0
light=CreateLight()
RotateEntity light,45,45,0
; A 20 x 20 m yard, 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
; A wall across the yard with a doorway 1.4 m wide
wall_left=Block(-5.35,0,3,9.3,1.5,0.5)
wall_right=Block(5.35,0,3,9.3,1.5,0.5)
; A guard holding the doorway, and a villager standing in the open: both
; stand as NavWalkers, and a guard nobody can push
guard=Character(0,3,220,60,60)
EntityNavWalker guard
pushable=False
WalkPushable guard,pushable
villager=Character(-5,-2,90,140,220)
EntityNavWalker villager
; The player, which NavWalkers make way for and are pushed by, and which
; slides along walls and round the walkers it bumps into
player=Character(0,-7,240,200,40)
NavWalkersAvoid player
EntityType player,1
EntityRadius player,0.35
EntityType guard,2
EntityRadius guard,0.35
EntityType villager,2
EntityRadius villager,0.35
EntityType wall_left,3
EntityType wall_right,3
Collisions 1,2,1,2
Collisions 1,3,2,2
While Not KeyDown(1)
; Space: the guard can be pushed, or can't
If KeyHit(57) Then
pushable=Not pushable
WalkPushable guard,pushable
EndIf
; Arrow keys walk the player: up and down go, left and right turn
If KeyDown(200) Then MoveEntity player,0,0,0.05
If KeyDown(208) Then MoveEntity player,0,0,-0.05
If KeyDown(203) Then TurnEntity player,0,3,0
If KeyDown(205) Then TurnEntity player,0,-3,0
UpdateWorld
RenderWorld
Text 0,0,"Arrow keys: walk the player (yellow) Space: guard pushable Esc: exit"
If pushable Then
Text 0,20,"WalkPushable guard,True: the player can shove it out of the doorway"
Else
Text 0,20,"WalkPushable guard,False: it holds the doorway"
EndIf
Text 0,40,"Walk into the villager (blue) too: it can always be pushed"
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