Movement in conjunction with mouselook

Blitz3D Forums/Blitz3D Programming/Movement in conjunction with mouselook

MajesticSpaceBen(Posted 2013) [#1]
I'm making an fps at the moment and have encountered an issue. I have mouselook working, but as a result the character flies in the direction the mouse is looking. I have been advised to use translateEntity, but this merely moves the player along the global x/z axis.

;game loop
While Not KeyHit(1)

	A# = .5 ;movement speed
	
	
	;mouselook
	mxs# = mxs# + MouseXSpeed()
	mys# = mys# + MouseYSpeed()
	RotateEntity playerHull,mys#,-mxs,0
	MoveMouse 100,100
	
	If mxs# > 360 Then mxs# = 0 ;limits of y value of view
	If mxs# < 0 Then mxs# = 360 
	
	If mys# > 80 Then mys# = 80 ;limits of x value of view
	If mys# < -80 Then mys# = -80
	
	
	
	;movement commands
	If KeyDown(17)	Then ;forward movement
		MoveEntity playerHull,0,0,A#
		walking=1
	EndIf
	
	If KeyDown(31)	Then ;backwards movement
		MoveEntity playerHull,0,0,-A#
		walking=1
	EndIf
	
	If KeyDown(30) Then ;strafe left
		MoveEntity playerHull,-A#,0,0
		walking=1
	EndIf
	
	If KeyDown(32)	Then ;strafe right
		MoveEntity playerHull,A#,0,0
		walking=1
	EndIf
	
	;viewbobbing
	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

	;footsteps
 	If Sin(90+a1*2)<-.85
  		If  footstep_needed<>0
   			Color 255,255,255
   			PlaySound snd_step
   			footstep_needed=0
  		EndIf
 	Else
  	footstep_needed=1
 	EndIf
	
	walking = 0;
	
	UpdateWorld
	RenderWorld
	
	Text 10,575,"Movement Demo"
	
	Flip

Wend


Can anyone recommend a solution to this?


Yasha(Posted 2013) [#2]
The conventional solution is to set up an armature of at least two entities or pivots to represent your character: the first is rotated around the Y axis by the mouse's horizontal movement, and is the only one to be controlled by movement inputs; the second is parented to this, and is rotated around the X axis by the mouse's vertical movement. The camera can in turn be parented to the second pivot at a distance (or otherwise exploit its position and rotation using some manual math, however you set up the camera system). The player mesh is usually only attached to the first pivot since you don't want it to rotate up and down as well.

This arrangement means the second pivot is able to "eat" the vertical movements, applying them to the camera without letting them affect the movement of its parent.


EDIT: Or my tired idiot eyes could see you wanted a first-person solution... well, the 3PS version probably illustrates the mechanism better, since it has more moving parts; same principle applies to both perspectives.