Need help with jump code

Blitz3D Forums/Blitz3D Programming/Need help with jump code

Guy Fawkes(Posted 2009) [#1]
Hi all. I have been studying up on gravity and stuff like that, so i decided to use this code i found on the forums.

Now I modified it a little bit to what i wanted, but there are 2 problems on it.

The 1st problem is why everytime do i move, my screen flickers this weird line created from the sky sphere i made.

and the 2nd thing. why every once in a while does my player not move when he moves or jumps or lands?

image:



code:

Graphics3D 800,600, 32, 2

AntiAlias 1
WBuffer 1

SetBuffer BackBuffer()

;Collision Setup
Global MaxCol = MaxCollisions(3)
Dim Col(MaxCol)
CollisionSetup()

Global camera = CreateCamera()
CameraRange camera, .1, 9999

Global sky = CreateSphere(100.5)
EntityOrder sky, 10
ScaleEntity sky, 100, 100, 100
EntityColor sky, 68, 207, 252
FlipMesh sky

PositionEntity camera,0,5,-5

RotateEntity camera, 30, 0, 0

Global light = CreateLight()

Global cube = CreateCube()
EntityRadius cube, 1, 2

EntityType(cube, Col(1))

Global jump_value = 0
Global jump_flag = 0

;Lighting
SceneLight = CreateLight()
	
		groundtexture=CreateTexture(32,32,1+8)
		
		SetBuffer TextureBuffer(groundtexture)
		
		Color 80,80,80
		Rect 0,0,32,32,1
		
		Color 100,100,100
		Rect 0,0,32,32,0
		
		ScaleTexture groundtexture,2,2
		
		SetBuffer BackBuffer()
		Color 255,255,255
	
pl=CreatePlane()
	PositionEntity pl,0,-1,0
	EntityOrder pl, 1
	EntityTexture pl,groundtexture
	EntityPickMode pl,2
	EntityType pl,Col(2)
	EntityColor pl,255,255,255

While Not KeyHit(1)

PositionEntity sky, EntityX(cube), EntityY(cube), EntityZ(cube)

PositionEntity camera, EntityX(cube), EntityY(cube)+5, EntityZ(cube)-5

If Not KeyDown(42)
If KeyDown(200) Or KeyDown(208) Or KeyDown(17) Or KeyDown(31)
speed# = .1
jspeed# = 10
EndIf
Else If KeyDown(42)
If KeyDown(200) Or KeyDown(208) Or KeyDown(17) Or KeyDown(31)
speed# = .2
jspeed# = 10
EndIf
EndIf
tspeed# = speed#
acceleration# = Cos(jump_value)/jspeed#
TurnEntity cube, 0, (KeyDown(203)-KeyDown(205)) Or (KeyDown(30)-KeyDown(32))*tspeed#, 0
MoveEntity cube, 0, 0, (KeyDown(200)-KeyDown(208))*speed#

gravity# = gravity# - .01

If gravity# < -1 Then gravity# = -1

	If KeyHit(57) And jump_flag = 0 Then
		jump_flag = 1
	End If

	If jump_flag = 0 Then
	 y# = EntityY(cube)
	  gy# = EntityY(pl)
	   If y# <= gy# Then y# = gy# : gravity# = 0
		MoveEntity cube, 0, y#+gravity#, 0
	Else If jump_flag = 1 Then
		MoveEntity cube,0,acceleration#,0
		jump_value = jump_value + 2
		If jump_value >60 Then
			jump_flag = 2
		End If
	ElseIf jump_flag = 2 Then
		MoveEntity cube,0,-Cos(jump_value)/jspeed#,0
		jump_value = jump_value - 2
		If jump_value < 0 Then
			jump_flag = 0
			jump_value = 0
		End If
	End If

	UpdateWorld
	RenderWorld
	
	Text 10, 10, gravity#
	Text 10, 30, "Jump: "+EntityY(cube)
	
	Flip
Wend

Function MaxCollisions(number%)
	Return number
End Function

Function CollisionSetup()
	For mc = 2 To MaxCol
		Col(mc) = mc
		Col(1) = 1
		Collisions Col(1),Col(mc),2,2
	Next
End Function


ANY help is GREATLY appreciated! :)

~DS~


Guy Fawkes(Posted 2009) [#2]
btw. where the arrow is, there is a blue line.

it flickers when i land, jump or move.


Kryzon(Posted 2009) [#3]
@1st

Yeah, you get that I think it's because of Direct3D's frustrum clipping. Don't know how to solve it. This problem you should have posted on Blitz3D Bug Reports, it's the best place for Mark or other team guy to check it out.


Guy Fawkes(Posted 2009) [#4]
well. it works fine IF its not inside of a sphere. and thats VERY unprofessional ><


Kryzon(Posted 2009) [#5]
Okay then, remove the sphere and add...
CameraCLSColor camera,255,128,64

...just below your camera creation line and then test it again.

Remember to remove the sphere.


Guy Fawkes(Posted 2009) [#6]
tried that. did the same thing..


Warner(Posted 2009) [#7]
I'm not sure what the problem is, but you don't need to scale the sphere 100times. 2 or 3 times is fine.
ScaleEntity sky, 100, 100, 100

Also, instead of placing it onto the cube, place it onto the camera:
PositionEntity sky, EntityX(camera,1), EntityY(camera,1), EntityZ(camera,1), 1
Right before calling RenderWorld.

The flickering, isn't that related to using 'WBuffer 1'? That disables z-buffering.


Guy Fawkes(Posted 2009) [#8]
possibly. :3


Kryzon(Posted 2009) [#9]

tried that. did the same thing..


You mean, that line on the left side still showed up?


Guy Fawkes(Posted 2009) [#10]
yup


Kryzon(Posted 2009) [#11]
Good. Then that means that that line isn't caused by the sphere. It's something else.


Guy Fawkes(Posted 2009) [#12]
then what is it?


Kryzon(Posted 2009) [#13]
Whatever it is, someone in Bug Reports will tell you. Trust me, if you point this issue there, important people will look it up.

PS: I have no idea what it is. Like I said, it can be something related to polygon clipping with planes created with CreatePlane().
At least whenever I noticed this error in a demo, it used a plane created with CreatePlane().


Gabriel(Posted 2009) [#14]
Is there some reason that you haven't tested without setting the WBuffer to true? Warner asked you about it, but all you said was "possibly".

You may as well leave out the AntiAlias true call also, as it doesn't work.

You might also try drastically reducing your near/far plane ratio. It's very high at the moment, and that coupled with WBuffering could easily cause problems. I'd try

CameraRange 1,500

You'll probably have to reduce the size of your skysphere to keep it visible, but that shouldn't be a problem as you are already using EntityOrder to ensure it's rendered last.


Ross C(Posted 2009) [#15]
I would personally get rid of the scaled part of the 3d window. It could be a graphics card issue when a resiable 3d area is displayed. Try full screen and fixed windowed mode. And yeah, reduce the size of your camera range ratio. It should generally not go above 10000:1