Camera movement not in sync with player

Blitz3D Forums/Blitz3D Programming/Camera movement not in sync with player

A51M15X(Posted 2010) [#1]
Whenever I move around the camera moves at a different rate than the player. This causes the movement to get out of sync. I'm still pretty new at this so any help is much appreciated.


While Not KeyDown(1)


PositionEntity player, x#, y#, z#
;PositionEntity camera, x#, y#, z#

	x#=x#+xspeed#
	z#=z#+zspeed#
	;y#=y#+.2

	xspeed#=xspeed#*.90
	zspeed#=zspeed#*.90

forward=KeyDown(17)
back=KeyDown(31)
moveleft=KeyDown(30)
moveright=KeyDown(32)
mouse1=MouseHit(1)
mouse2=MouseHit(2)
space=KeyDown(57)

If forward Then zspeed#=zspeed#+.5
If back Then zspeed#=zspeed#-.5
If moveleft Then xspeed#=xspeed#-.5
If moveright Then xspeed#=xspeed#+.5
If space Then y#=y#+1

h# = h# + MouseXSpeed()/6.0
g# = g# + MouseYSpeed()/6.0

If g < -80 Then g = -80
If g > 80 Then g = 80

RotateEntity camera, g, 0, 0
RotateEntity player, 0, -h, 0

MoveMouse GraphicsWidth()/2, GraphicsHeight()/2

UpdateWorld()

RenderWorld()

Flip
Wend
End



Yes, I know i still have to fix the y# movement, but i'd like to fix the camera thing first.


Oiduts Studios(Posted 2010) [#2]
Well before anyone looks at the code they will probably tell you to pivot the camera around the player instead of repositioning it manually.


A51M15X(Posted 2010) [#3]
What do you mean?

This is what I have:

player = CreatePivot()
camera = CreateCamera(player)



lo-tekk(Posted 2010) [#4]
This should work better, look into the UpdateGame() function: