EntityCharacter
Makes an entity a character that walks, jumps and climbs steps.
EntityCharacter ( entity[,radius#][,height#][,step#][,slope#] )
Parameters
- entity
- the entity to make a character. Its origin is at the character's feet
- radius# (optional)
- how wide the character is, from the middle to the edge. Defaults to 0.4
- height# (optional)
- how tall the character is. Defaults to 1.8
- step# (optional)
- the highest step it can walk straight up. Defaults to 0.3
- slope# (optional)
- the steepest slope, in degrees, it can walk up. Defaults to 45
Description
Makes an entity a character: a body that walks, jumps, climbs steps and walks up slopes, the way players and people in games move. Gravity pulls it down, walls and steep slopes stop it, and it pushes physics bodies out of its way.
Sizes are in world units, whatever the entity's scale, so a model can be scaled to fit without changing how the character moves. The character stays upright: turn it with TurnEntity or RotateEntity and only its yaw counts.
Move it with CharacterWalk and CharacterJump, then call UpdateWorld. GetEntityPhysics returns 5 for a character. EntityPhysics entity,0 turns it back into a plain entity.
Example
; Physics characters example (an ArcBasic extension); A character that walks, jumps, climbs steps and slopes and pushes crates.; Arrows: walk and turn Space: jump P: push harderGraphics3D 640,480SetBuffer BackBuffer()light=CreateLight()RotateEntity light,50,30,0ground=CreatePlane()EntityColor ground,70,90,70EntityPhysics ground,1; stairs: each step a quarter of a unit higher than the lastFor i=1 To 4 s=CreateCube() ScaleEntity s,1.5,i*.125,1 PositionEntity s,-5,i*.125,3+i*2 EntityColor s,150,150,170 EntityPhysics s,1Next; a gentle ramp and one too steep to walk upramp=CreateCube()ScaleEntity ramp,1.5,.1,4PositionEntity ramp,0,1.2,6RotateEntity ramp,-20,0,0EntityColor ramp,170,140,100EntityPhysics ramp,1steep=CreateCube()ScaleEntity steep,1.5,.1,3PositionEntity steep,5,1.4,5RotateEntity steep,-60,0,0EntityColor steep,200,90,80EntityPhysics steep,1; crates to push aboutFor i=0 To 5 c=CreateCube() ScaleEntity c,.4,.4,.4 PositionEntity c,-3+i*1.2,.4,-4 EntityColor c,200,160,90 EntityPhysics c,2,.5Next; the hero: a pivot at its feet carrying a body and a nose that shows which way it faceshero=CreatePivot()body=CreateCylinder(16,True,hero)ScaleEntity body,.4,.9,.4PositionEntity body,0,.9,0EntityColor body,90,160,255nose=CreateCube(hero)ScaleEntity nose,.12,.12,.25PositionEntity nose,0,1.5,.45EntityCharacter hero,.4,1.8,.3,45camera=CreateCamera(hero)PositionEntity camera,0,4,-8TurnEntity camera,20,0,0push#=1While Not KeyHit(1) If KeyDown(203) Then TurnEntity hero,0,3,0 If KeyDown(205) Then TurnEntity hero,0,-3,0 speed#=0 If KeyDown(200) Then speed=4 If KeyDown(208) Then speed=-2 CharacterWalk hero,0,speed If KeyHit(57) Then CharacterJump hero,6 If KeyHit(25) Then push=4-push : CharacterPush hero,push UpdateWorld RenderWorld Text 0,0,"Arrows: walk and turn Space: jump P: push harder" If CharacterOnFloor(hero) Then floor$="on the floor" Else floor$="in the air" Text 0,15,"The hero is "+floor$+" push strength "+push FlipWendEnd
