Gravity?!?!?

Blitz3D Forums/Blitz3D Beginners Area/Gravity?!?!?

W
 #1
Hey guys, can anyone show me how to make decent gravity effects, without buying a physics engine or program?? I have tried a few ways, but none of them look good. I am implementing gravity into my FPS, and I need it to look decent, I am using a camera on a pivot type player.
-Any help would be appreciated!!

Graphics3D 640,480

SeedRnd MilliSecs()

PlayerPhysicsPivot = CreatePivot()
Player = CreateSphere(6)

; Lights and Camera
Camera = CreateCamera()
PositionEntity camera,0,20,-20
TurnEntity camera,30,0,0
Light = CreateLight(2)
PositionEntity Light,1000,1000,0

; Create the Ground
Ground = CreatePlane()
GroundTex = CreateCheck()
ScaleTexture GroundTex,10,10
EntityTexture Ground,GroundTex
EntityAlpha Ground,.6
Mirror = CreateMirror()
PositionEntity Mirror,0,-.1,0

; Position the player start point
PositionEntity Player,0,40,0


; amount of force to apply to entity
Force# = 0.02

Repeat


	; Player input force
	If KeyDown(200) Then TranslateEntity PlayerPhysicsPivot,0,0,Force#
	If KeyDown(208) Then TranslateEntity PlayerPhysicsPivot,0,0,-Force#
	If KeyDown(203) Then TranslateEntity PlayerPhysicsPivot,-Force#,0,0
	If KeyDown(205) Then TranslateEntity PlayerPhysicsPivot,Force#,0,0
	
	; Jump
	If KeyHit(57) Then TranslateEntity PlayerPhysicsPivot,0,1,0
	
	; Gravity Force
	TranslateEntity PlayerPhysicsPivot,0,-.01,0
		
	
	; Drag, the 0.1 is how much drag, the higher the figure the more drag (from 0 to 1)
	drag# = 0.1
	TranslateEntity PlayerPhysicsPivot,-EntityX(PlayerPhysicsPivot)*drag,0,-EntityZ(PlayerPhysicsPivot)*drag

	
	TranslateEntity Player,EntityX(PlayerPhysicsPivot),EntityY(PlayerPhysicsPivot),EntityZ(PlayerPhysicsPivot)

	; Check for the ground and bounce
	If EntityY(Player)<0.5
	
		; How bouncy the player is, 0 being not bouncy at all, 1 being 100% bouncy
		Bounce# = 0.5
	
		TranslateEntity Player,0,0.5 - EntityY(player),0
		TranslateEntity PlayerPhysicsPivot,0,-EntityY(PlayerPhysicsPivot)*(1+bounce),0
	EndIf
		
	RenderWorld
	Flip
	
Until KeyHit(1)



Function CreateCheck()
	i = CreateImage(256,256)
	t = CreateTexture(256,256)
	
	SetBuffer ImageBuffer(i)
	
	Color 0,0,255
	Rect 0,0,128,128
	Rect 128,128,128,128
	Color 0,100,200
	Rect 128,0,128,128
	Rect 0,128,128,128
	
	CopyRect 0,0,256,256,0,0,ImageBuffer(i),TextureBuffer(t)
	FreeImage i
	Return t
End Function




Yikes, that seems a little convoluted to me, Rob.

My approach would be to use objects (Types) to keep track of the velocities of physical bodies. See my post in this discussion for an explanation and an example.

Octothorpe, I find using a pivot to deal with velocities very simple, it also means to add a shunt force at 10 degress for example you simply rotate the physics pivot to the direction of the shunt and move it with however much force you want.

It also means you're only using one handle for all the forces acting on a body which to me seem simpler and can be controlled using all the standard entity functions

Interesting. I suppose it does do the trick! :)

To each his own, as the proverb goes.