How do you make an entity walk up stairs?
Walking up stairs
Blitz3D Forums/Blitz3D Beginners Area/Walking up stairs First you move the entity up when it walks. Then you move it forwards. Then you move it down. You must call UpdateWorld() after moving it up. Example:
If Keydown(208) MoveEntity Person,0,10,0 UpdateWorld() MoveEntity Person,0,0,10 UpdateWorld() MoveEntity Person,0,-10,0 endif
if its 3d set collision responce to 2 and the radius to a value that makes it "float" sorta off the ground. then when you hit stairs you slide over them but you can animate your caracter in such a way as to make it look like he's walking up the stairs.
This has been discussed to death in the past - use the search function.
You can also create an invisible quad as a ramp just above your stairs and give that quad collisions (response-type 3 prevents your character to slide down this ramp when not moving).
Then your character will use this ramp to "slide" it's way to the top of the stairs, just moving your character forwards will do the trick.
Then your character will use this ramp to "slide" it's way to the top of the stairs, just moving your character forwards will do the trick.
The quad idea is the best one tbh.
This is the function that checks the controls for your character (its a FPS). I've also included the function that checks the physics. You can walk up stairs normally when you are going sideways but not when you are going forward. Please tell me if you find anything in here that I could change to fix it.
;--------------------------------------------------------------
;CONTROLS
Function controls()
If rifleselected=1
DrawImage aimer,355,255
EndIf
If pistolselected=1
DrawImage aimer2,355,255
EndIf
If KeyDown( 54 ) =1
WalkSpeed# = .05
Else
WalkSpeed# = .5
EndIf
If KeyDown( 57 ) =1 And Jumped =0
Jumped =1
EndIf
If KeyHit(2)
Animate rifle,3,.2,1
HideEntity rifle
ShowEntity pistol
Animate pistol,3,-.2,1
pistolselected=1
rifleselected=0
weaponout=1
End If
If KeyHit(3)
Animate pistol,3,.2,1
HideEntity pistol
ShowEntity rifle
Animate rifle,3,-.2,1
pistolselected=0
rifleselected=1
weaponout=1
End If
; Keys for movement
If FlyMode=0
If KeyDown(17) =1 Then MoveEntity CamPivot, 0, 0, WalkSpeed# Animate rifle,3,.2,2 UpdateWorld()
If KeyDown(31) =1 Then MoveEntity CamPivot, 0, 0, 0-WalkSpeed#
PositionEntity Camera, EntityX#( CamPivot ), EntityY#( CamPivot )+8, EntityZ#( CamPivot )
EndIf
If KeyDown(30) =1 Then MoveEntity CamPivot, -1, 0, 0
If KeyDown(32) =1 Then MoveEntity CamPivot, 1, 0, 0
If EntityCollided(CamPivot,2)
Jumped=0
Gravity#=0
EndIf
TranslateEntity CamPivot, 0, Gravity#, 0
TurnEntity CamPivot, 0, 0 -MouseXSpeed(), 0
TurnEntity Camera, MouseYSpeed(), 0, 0
RotateEntity CamPivot, EntityPitch#( CamPivot ), EntityYaw#( CamPivot ), 0
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
RotateEntity Camera, EntityPitch#( Camera ), EntityYaw#( CamPivot ), 0
physics()
If KeyHit(20)
Lazer=1
EndIf
If KeyHit(20)And Lazer=1
Lazer=0
EndIf
If ammo=0 Or ammo<0 And KeyHit(19)And machineguncartriges>0
Animate rifle,3,-.2,3
ammo=100
machineguncartriges=machineguncartriges-1
EndIf
If MouseHit(1)And pistolselected=1 And pistolammo>0
createbullet(Camera)
EndIf
If MouseDown(1) And rifleselected=1 And ammo>0
If MilliSecs()>delaytime Then
delaytime=MilliSecs()+800
createbullet(Camera)
ammo=ammo-1
EndIf
EndIf
updatesparks(sparks)
Flip
UpdateWorld()
RenderWorld
HideEntity muzzle
HideEntity muzzleglow
HideEntity muzzleglow2
Return
End Function
;--------------------------------------------------------------
Function physics()
Collisions 1,2,2,2
UpdateWorld()
ClearCollisions
End Function
;--------------------------------------------------------------
;Load Player
Global CamPivot = CreatePivot( )
Global Camera = CreateCamera( )
CameraRange Camera,.2,1000
CameraFogMode Camera,1
CameraFogRange Camera,.2,999
CameraFogColor Camera,19,164,149
PositionEntity CamPivot,1010,50,1010
EntityType CamPivot, 1
EntityRadius CamPivot, 6
EntityType Camera, 1
EntityRadius Camera, 2
;--------------------------------------------------------------
;CONTROLS
Function controls()
If rifleselected=1
DrawImage aimer,355,255
EndIf
If pistolselected=1
DrawImage aimer2,355,255
EndIf
If KeyDown( 54 ) =1
WalkSpeed# = .05
Else
WalkSpeed# = .5
EndIf
If KeyDown( 57 ) =1 And Jumped =0
Jumped =1
EndIf
If KeyHit(2)
Animate rifle,3,.2,1
HideEntity rifle
ShowEntity pistol
Animate pistol,3,-.2,1
pistolselected=1
rifleselected=0
weaponout=1
End If
If KeyHit(3)
Animate pistol,3,.2,1
HideEntity pistol
ShowEntity rifle
Animate rifle,3,-.2,1
pistolselected=0
rifleselected=1
weaponout=1
End If
; Keys for movement
If FlyMode=0
If KeyDown(17) =1 Then MoveEntity CamPivot, 0, 0, WalkSpeed# Animate rifle,3,.2,2 UpdateWorld()
If KeyDown(31) =1 Then MoveEntity CamPivot, 0, 0, 0-WalkSpeed#
PositionEntity Camera, EntityX#( CamPivot ), EntityY#( CamPivot )+8, EntityZ#( CamPivot )
EndIf
If KeyDown(30) =1 Then MoveEntity CamPivot, -1, 0, 0
If KeyDown(32) =1 Then MoveEntity CamPivot, 1, 0, 0
If EntityCollided(CamPivot,2)
Jumped=0
Gravity#=0
EndIf
TranslateEntity CamPivot, 0, Gravity#, 0
TurnEntity CamPivot, 0, 0 -MouseXSpeed(), 0
TurnEntity Camera, MouseYSpeed(), 0, 0
RotateEntity CamPivot, EntityPitch#( CamPivot ), EntityYaw#( CamPivot ), 0
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2
RotateEntity Camera, EntityPitch#( Camera ), EntityYaw#( CamPivot ), 0
physics()
If KeyHit(20)
Lazer=1
EndIf
If KeyHit(20)And Lazer=1
Lazer=0
EndIf
If ammo=0 Or ammo<0 And KeyHit(19)And machineguncartriges>0
Animate rifle,3,-.2,3
ammo=100
machineguncartriges=machineguncartriges-1
EndIf
If MouseHit(1)And pistolselected=1 And pistolammo>0
createbullet(Camera)
EndIf
If MouseDown(1) And rifleselected=1 And ammo>0
If MilliSecs()>delaytime Then
delaytime=MilliSecs()+800
createbullet(Camera)
ammo=ammo-1
EndIf
EndIf
updatesparks(sparks)
Flip
UpdateWorld()
RenderWorld
HideEntity muzzle
HideEntity muzzleglow
HideEntity muzzleglow2
Return
End Function
;--------------------------------------------------------------
Function physics()
Collisions 1,2,2,2
UpdateWorld()
ClearCollisions
End Function
;--------------------------------------------------------------
;Load Player
Global CamPivot = CreatePivot( )
Global Camera = CreateCamera( )
CameraRange Camera,.2,1000
CameraFogMode Camera,1
CameraFogRange Camera,.2,999
CameraFogColor Camera,19,164,149
PositionEntity CamPivot,1010,50,1010
EntityType CamPivot, 1
EntityRadius CamPivot, 6
EntityType Camera, 1
EntityRadius Camera, 2
It's alot easier to place a quad :o)
Also, don't use the collisions command every loop, unless your disabling it every loop too.
Also, don't use the collisions command every loop, unless your disabling it every loop too.
Thanks, it works now!
Oh and feel free to use the code, if you want to, just enter me in the credits of your game.