Pesky ol' gravity... always ruining my plans...

Blitz3D Forums/Blitz3D Beginners Area/Pesky ol' gravity... always ruining my plans...

Hey again! I'm trying to insert gravity into a sphere movement test (which is also failing miserably, by the way), and when I say:
player\yinertia# = player\yinertia# - gravity#

the sphere starts floating upwards. But if instead, I say:
player\yinertia# = player\yinertia# + gravity#

the sphere shoots upwards extremely quickly. I want it to stay down, not go up! Help!

In addition, I have other problems...

The line: "If EntityCollided(player\sphere, 1) > 0" doesn't seem to work.

Also, the following jump function doesn't work.

If player\jumping = 1
	
			player\yinertia# = player\yinertia# + player\jump#
		
			player\jump# = player\jump# - .01
		
		If player\yinertia# = 0
		
			player\jumping = 0
			
		EndIf
		
	EndIf


After the ball touches the ground from jumping, it starts floating upwards, and I think this might have to do with the first problem.

Help me... I'm a mess!

You don't have to do wxactly on the first problem you can juist have the shpere canstatnly moving down and by using the TranslateEntity set the y (2nd in xx,yy,zz for newcomers) it around -20 (note you can stilll move the sphere upward after this but at the second problem why not translate ther entity up fo about say 15 (easier way)

Buggy,

Here's a simple example using accumulated acceleration forces which should help you.

Press space to jump.

Stevie


Graphics3D 640,480,16,1

Const GRAVITY# = 9.8
Const TIMESTEP# = .05
Const C_PLAYER = 1
Const C_GROUND = 2
Collisions C_PLAYER, C_GROUND, 2, 3

Global CAMERA = CreateCamera() : PositionEntity CAMERA, 0,10,-20
Global LIGHT = CreateLight()
Global PLANE = CreatePlane() : EntityType PLANE, C_GROUND : EntityColor PLANE, 200,100,100
Global BALL = CreateSphere() : EntityType BALL, C_PLAYER : HideEntity BALL
Global SHADOW = CreateSphere() : ScaleMesh SHADOW, 1, .01, 1 : EntityColor SHADOW,32,32,32 : HideEntity SHADOW

Type Player
	Field Mesh
	Field Shadow
	Field Vx#, Vy#, Vz#
	Field Ax#, Ay#, Az#
End Type

Global MY.Player = PLAYERcreate( 0 , 25, 0 )

While Not KeyDown(1)

	PLAYERupdate( MY )
	UpdateWorld()
	RenderWorld()
	
	Flip

Wend

;===============================================================
;===============================================================
;===============================================================

Function PLAYERcreate.player( x#, y#, z# )

	p.player = New player
	p\Mesh = CopyEntity ( BALL )
	p\Shadow = CopyEntity ( SHADOW )
	PositionEntity p\Mesh, x, y, z
	ResetEntity p\Mesh
	Return p
	
End Function

;===============================================================
;===============================================================
;===============================================================

Function PLAYERupdate( p.player )	

	;collision check
	If EntityCollided( p\Mesh, C_Ground )
		;bounce
		If p\vy < 0 p\vy = -p\vy*.75
		;jump
		If KeyDown( 57 ) p\Ay = p\Ay + 250.0
	EndIf
	
	;apply acceleration 
	p\Ay = p\Ay - GRAVITY
	p\vx = p\vx + p\ax * TIMESTEP * TIMESTEP
	p\vy = p\vy + p\ay * TIMESTEP * TIMESTEP
	p\vz = p\vz + p\az * TIMESTEP * TIMESTEP
	;move player
	TranslateEntity p\Mesh, p\vx, p\vy, p\vz
	;reset acceleration
	p\Ax# = 0
	p\Ay# = 0
	p\Az# = 0
	
End Function