Gravity not Working

Blitz3D Forums/Blitz3D Beginners Area/Gravity not Working

A51M15X(Posted 2009) [#1]
I got this code from Nate the Great and integrated it into my game, but it doesn't pull the player down or allow the player to move at all. Can you please take a look and find if theres something wrong?


;Use W A S D to try to move around...

Graphics3D 1024,768,0,2
SetBuffer BackBuffer()

Const PLAYER_COL= 1
Const GROUND_COL= 2

gravity# = -.01

player = CreatePivot()
camera = CreateCamera(player)
CameraRange camera,1, 9500000
CameraFogMode camera,1
CameraFogColor camera,200,230,255
CameraFogRange camera,1000,100000
CameraZoom camera,1.2

MoveEntity camera,0,15,0
MoveEntity player,0,5,0

plx# = 0
ply# = 0
plz# = 0

pldx# = 0
pldy# = 0
pldz# = 0

ground = CreatePlane()
PositionEntity ground,0,0,0
EntityColor ground,170,190,130

HidePointer()

EntityType player,PLAYER_COL
EntityRadius player,4,4.25
EntityType ground,GROUND_COL
Collisions PLAYER_COL,GROUND_COL, 2, 2

While Not KeyDown(1)
Cls

;TranslateEntity player,0,-.3,0

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

If ply < -2 Then
	ply = -2
	pldy = -pldy*.39
EndIf

If ply < -1.8 Then
	pldx = .6*pldx
	pldz = .6*pldz
	If KeyDown(57) Then pldy = .3
EndIf

pldy = pldy + gravity

plx = plx + pldx
ply = ply + pldy
plz = plz + pldz
	
PositionEntity player,plx,ply,plz

If forward Then MoveEntity player,0,0,.3
If back Then MoveEntity player,0,0,-.2
If moveleft Then MoveEntity player,-.2,0,0
If moveright Then MoveEntity player,.2,0,0

;If forward Then pldz = .3
;If back Then pldz = -.2
;If moveleft Then pldx = -.2
;If moveright Then pldx = .2

x# = x# + MouseXSpeed()/6.0
y# = y# + MouseYSpeed()/6.0

If y < -80 Then y = -80
If y > 80 Then y = 80

RotateEntity camera, y, 0, 0
RotateEntity player, 0, -x, 0

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

UpdateWorld()

RenderWorld()

Flip
Wend
End




AJ00200(Posted 2009) [#2]
I THINK its because of tha collisions.
Not on a ccomputer, so I cant check.


GIB3D(Posted 2009) [#3]
Probably has something to do with you using PositionEntity player,plx,ply,plz. Check the variables plx,ply,plz and what ever effects them too.


Spike314(Posted 2009) [#4]
Hi
Replace
PositionEntity player,plx,ply,plz


with

PositionEntity player,EntityX(player)+plx,EntityY(player)+ply,EntityZ(player)+plz



A51M15X(Posted 2009) [#5]
Thanks Spike it works perfectly now.