Collisions Problem

Blitz3D Forums/Blitz3D Programming/Collisions Problem

amitjf(Posted 2009) [#1]
Hello
Long time I havn't used b3d so I'm pretty sure I'm doing something wrong. I've searched the forum for help, but none worked.
Anyway, here's my code:

If Windowed3D()
		Graphics3D 1024,800,0,2
Else
		Graphics3D 1024,800,0,1
EndIf

	;MODEL
		fil$="Shming4.b3d"
	model=LoadAnimMesh( fil$ )
	If model=0 RuntimeError "Unable to load 3D mesh:"+fil$
	ScaleEntity model,0.01,0.01,0.01
	PositionEntity model,0,200,0
	animman=FindChild(model,"Cylinder02")
	animichael=FindChild(model,"Bip01")
	EntityRadius animman,1,1
	EntityRadius animichael,1,1
	EntityRadius model,1,1

	EntityType animman,1
	EntityType model,1
	EntityType animichael,1

	;;MODEL SEQ
	StartWalk_SEQ=ExtractAnimSeq(animman,0,19)
	Walk_SEQ=ExtractAnimSeq(animman,20,42)
	StopWalk_SEQ=ExtractAnimSeq(animman,43,97)
	
	;CAMERA
	camera=CreateCamera(animichael)
	CameraRange camera,0.1,100000000
	PositionEntity camera,-700,500,0
	PointEntity camera,animichael
	light=CreateLight()
	TurnEntity light,45,45,0
	
	;SKY
	Global sky = CreateSphere(16,camera)
	FlipMesh sky
	ScaleEntity sky,10000,10000,10000
	PositionEntity sky, 0,50,0
	sky_tex = LoadTexture("media\sky.bmp")
	EntityTexture sky,sky_tex

	;TERRAIN
	Global terrain = LoadTerrain("media\height3.jpg")
	TerrainDetail terrain,2500,True
	ScaleEntity terrain, 3,15,3
	PositionEntity terrain,-20,-8,-20
	ter_tex = LoadTexture("media\mossyground.bmp")
	EntityTexture terrain,ter_tex
	EntityRadius terrain,1,1
	EntityType terrain,2
	
	movehasdone=False
	WalkKeyUp=False
	collisiontext=False
	
	Collisions 1, 2, 1, 2
	
	Repeat
		If EntityCollided(model,2)
			collisiontext=True
		End If

		MoveEntity model,0,-1,0
			If KeyHit(1) End
			If KeyDown(200) TurnEntity model,0,0,0;Up
			If KeyDown(208) TurnEntity model,0,0,0;Down
			If KeyDown(203) TurnEntity model,0,1,0;Left
			If KeyDown(205) TurnEntity model,0,-1,0;Right
			If KeyHit( 17) Then ;W
				Animate animman,3,0.8,StartWalk_SEQ,10
				movehasdone=False
				walkkeyup=True
			End If
			If KeyDown(17) And Animating(animman)=False And movehasdone=True Then
				Animate animman,3,0.8,Walk_SEQ,5
				movehasdone=False
				walkkeyup=True
			End If
			If Animating(animman)=False And movehasdone=True And walkkeyup=True Then
				Animate animman,3,0.8,StopWalk_SEQ,10
				movehasdone=False
				walkkeyup=False
			End If
			If Animating(animman)=False And movehasdone=False Then
		 		PositionEntity model,EntityX(animichael,True),EntityY(animichael,True),EntityZ(animichael,True)
				PositionEntity animichael,0,0,0
				movehasdone=True
			End If
			
			;If KeyDown( 30);A
			;If KeyDown( 31);S
			;If KeyDown( 32);D
			;If KeyDown( 44);Z
			;If KeyDown( 45);X	

		UpdateWorld
		RenderWorld
		Text 0,10,"x:"+EntityX(model)+" y:"+EntityY(model)+" z:"+EntityZ(model)+",col:"+collisiontext

		Flip
	Forever


the b3d model is an animated model, created in 3d studio max, animated using biped skin and a .bip file, and exported using b3d pipeline.

I would really appreciate any help!
Thanks in advance


Adam Novagen(Posted 2009) [#2]
Well, as we can't actually run your code properly without the model you're using, it'd help if you described the actual problem you're having.

Anyway, looking at your code, I can see one potential problem: you're using Sphere-to-Sphere collision checking for your player-to-terrain collisions. In my experience, S2S collisions should literally only be used between two balls, and a terrain by nature can't be a ball. If you use Sphere-to-Polygon (method 2) instead, that might fix the problem.


_PJ_(Posted 2009) [#3]
-Edited--

. Nevermind, I re-read the title. :)
THough some information on just what the problem is might help.


amitjf(Posted 2009) [#4]
Well thanks for the help. I'll check whether the S2S method is the issue later today. The problem I'm having is that the collision just won't work. I placed the character very high above the terrain and moved it slowly toward it. I defined a collision between their types but when the character gets to the terrain it just continue moving down through it. Even using EntityCollided won't work.

EDIT:
Yes thank you, the S2S was the issue! Changed to Sphere 2 Polygon and now it works.