First Person Walking\Running Simulation??

Blitz3D Forums/Blitz3D Beginners Area/First Person Walking\Running Simulation??

W(Posted 2005) [#1]
Alright guys, sorry to keep bothering you, but I keep getting stuck on what the best way to simulate the minor movements of a first person view walk and run. Any Suggestions?

-I already have the walk key assigned to move the camera
and I got it set up when you hold down shift and press the walk key the player will run..

--Any Help Appreciated


WolRon(Posted 2005) [#2]
I'm not entirely sure what you are looking for but maybe having a look at my FPS example code (at my Programming Tutorial) may help.


W(Posted 2005) [#3]
When a person walks they move slightly up and down in succession.So using the first person view I want the camera to move slightly up and down with the walk or run of the player.
Im having a rough time with it...
Thanks!! for the site suggestion, I didn't find what I was looking for, but it gave me lots of ideas on how other things work


Ross C(Posted 2005) [#4]
Look into using SIN to move the camera up and down in a bob.


jfk EO-11110(Posted 2005) [#5]
use a pivot for the player, then stick the camera to it using EntityParent.
you will then move the player pivot to move the camera, rotate the cameras pitch to look up and down (MouseYSpeed()) and rotate the players pivot yaw to turn left and right (MouseXSpeed). This way your walking speed will be constant, no matter if you look down or straight forward etc.

Now since the camera is parented to the player pivot, you can use a sin/cos offset that is relative to the player pivot, eg:

positionentity camera,sin(a)*3.0,cos(b)*3.0,0,0 
;(note the last Zero is to define the position to be relative to the parent)
If walking=1 then 
 a=(a+1)mod 360
 b=(b+2)mod 360
endif


You may have to fiddle a bit to find the right sin and cos values.


W(Posted 2005) [#6]
Could you please show me an example in action jfk???


jfk EO-11110(Posted 2005) [#7]

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

player=CreatePivot()
PositionEntity player,0,3,0
EntityRadius player,.9
EntityType player,1

camera=CreateCamera( player )
TranslateEntity camera,0,0.9,0
CameraRange camera,.1,200

tex=CreateDummyTexture(256,256)
ScaleTexture tex,10,10

ground=CreatePlane() ; or the map mesh etc.
EntityTexture ground,tex
EntityType ground,2


sp#=.05 ; main walking speed (not connected with wobbling)
shoe_size#=7.0 ; stepspeed for wobbling camera (eg. 7=running, 4=walking)
head_bang_X#=0.1 ; amount of wobbling
head_bang_Y#=0.1

Collisions 1,2,2,2

While Not KeyHit(1)


 mxs#=MouseXSpeed()/4.0
 mys#=MouseYSpeed()/4.0
 MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
 camxa#=camxa-mxs Mod 360
 camya#=camya+mys
 If camya<-90 Then camya=-90
 If camya>90 Then camya=90
 RotateEntity player,0,camxa,0
 RotateEntity camera,camya,0,0

 MoveEntity player,0,-.05,0 ; simplified gravity

 walking=0
 If KeyDown(203) Then: MoveEntity player,-sp,0,0 : walking=1: EndIf
 If KeyDown(205) Then: MoveEntity player, sp,0,0 : walking=1: EndIf
 If KeyDown(200) Then: MoveEntity player,0,0, sp : walking=1: EndIf
 If KeyDown(208) Then: MoveEntity player,0,0,-sp : walking=1: EndIf


 ; >>>>>>>>>wobble camera
 If walking=1
  a1#=(a1#+shoe_size) Mod 360
  Else
  ;a1#=a1#*0.8
 EndIf
 PositionEntity camera,Cos(a1#)*head_bang_X#,Sin(90+a1#*2)*head_bang_Y#,0,0
; PositionEntity camera,Cos(a1#)*head_bang_X#,Sin(270+a1#*2)*head_bang_Y#,0,0 ; or try this one instead!

 UpdateWorld
 RenderWorld

 ; >>>>>>>>>control footstep sound
 If Sin(90+a1*2)<-.85
  If  footstep_needed<>0
   Color 255,255,255
   Text 50,50, "Tap!" ; play a footstep sound here!
   footstep_needed=0
  EndIf
 Else
  footstep_needed=1
 EndIf




 VWait:Flip 0
Wend

End

Function CreateDummyTexture(w,h)
 tex=CreateTexture(w,h)
 SetBuffer TextureBuffer(tex)
  Color 255,255,255
  For i=0 To 1000
   Color Rand(255),Rand(255),Rand(255)
   Line Rand(0,w-1),Rand(0,h-1),Rand(0,w-1),Rand(0,h-1)
  Next
 SetBuffer BackBuffer()
 Return tex
End Function



jfk EO-11110(Posted 2005) [#8]
well the variable shoe_size doens't describe its purpose very correctly: the lower the value the bigger the stepwidth. So it's more a Step-Frequence.


W(Posted 2005) [#9]
Sweet, thanks jfk hey while your on a roll here do you mind giving a guy a rundown and explanation of how to use animations with my models and using nodes to allow my models to navigate my world.


jfk EO-11110(Posted 2005) [#10]
that's a complex topic and I rather suggest to read existing works as well as check out the code archives. BTW I don't use nodes, but a simple waypoint system in my engine.