Collision Problem-How to keep character on varying ground levels?!!!

Blitz3D Forums/Blitz3D Programming/Collision Problem-How to keep character on varying ground levels?!!!

KovaSteel(Posted 2003) [#1]
While programming the controls for my game ,i got stuck on a collision problem which is pestering me for some times!!! Please help!

How can i keep my character walking on the ground of my level(created in a modelling package,so it is not a terrain)??!!When the height of the ground is the same everywhere,there`s no problem since i can position the character on it(Like PositionEntity character,0,fixedheightofcharacterabovegroud,0) and everything will work ok. But when it comes to varying gound levels,like climbing stairs or crossing bridges,then it gets messy. I tried this after some tries but it didn`t work(This code is ONLY only for lowering the character`s heigt):

y#=character current height
Entitytype character,1
Entitytype level,2
If Not(Entitycollided character,2) then Positionentity character 0,y#-.1,0

I first thought that it would test to see if the character is touching the ground and then reduce it`s height until it does but unfortunately it isn`t working. My character is half in the ground when i use this but when i walk DOWN the stairs. My characters height about the ground is reduced to that of the stairs but my character still half stuck in the ground. Please help!!!!!!


Shambler(Posted 2003) [#2]
I just do a linepick straight down and alter the players position based on the PickedY#() and the players YPosition.

This way you can smooth out stairs so the camera doesn't bump up and down them.

LinePick EntityX#(p\head,True),EntityY#(p\head,True),EntityZ#(p\head,True),0,-50,0

currentheight#=EntityY#(p\head,True)-PickedY#()
currentpicked=PickedEntity()

If currentpicked<>0
If currentheight#<p\height#
MoveEntity p\head,0,(p\height#-currentheight#)/10,0
EndIf
If currentheight#>p\height#
MoveEntity p\head,0,-(currentheight#-p\height#)/5,0
EndIf
EndIf 




Rob(Posted 2003) [#3]
works for me...
;set up variables
Const c_player=1,c_level=2
Global player_radius# = 0.2
Global player_height# = 0.4
Global player_step#   = 1
gravity#=0
vx#=0
vy#=0
vz#=0


;create display
HidePointer
Graphics3D 640,480,16,2
camera=CreateCamera()

CameraRange camera,0.1,1000

;load files
level=LoadAnimMesh("temp.b3d")
playerpivot=CreatePivot();Sphere():EntityColor playerpivot,255,0,0:EntityAlpha playerpivot,0.25:EntityFX playerpivot,1

;set up scene
light=CreateLight(1)
TurnEntity light,45,0,0
LightColor light,128,128,128

light=CreateLight(1)
TurnEntity light,-45,180,0
LightColor light,64,64,128


;position player
PositionEntity playerpivot,0,50,0
ScaleEntity playerpivot,player_radius,player_height,player_radius

;set up collisions
EntityType playerpivot,c_player
EntityRadius playerpivot,player_radius,player_height

EntityType level,c_level,1
EntityPickMode level,2

For i=1 To CountChildren(level)
	EntityPickMode GetChild(level,i),2
Next
	

Collisions c_player,c_level,2,2

AmbientLight 80,80,80


;set up chase cam
PositionEntity camera,EntityX(playerpivot),EntityY(playerpivot),EntityZ(playerpivot)
PointEntity camera,playerpivot
MoveEntity camera,0,player_height,0
EntityParent camera,playerpivot


While Not KeyHit(1)
	UpdateWorld
	RenderWorld
	Gosub physics
	MoveMouse 320,240
	Flip
Wend
End

.physics:

	;physics
	vxspd# = 0.025
	vyspd# = 0.05
	vzspd# = 0.025
	inertia# = 0.8
	gravity# = -1
	mousedampx#=0.15
	mousedampy#=0.12
	
	;input
	impulseforward = KeyDown(17)
	impulseback = KeyDown(31)
	impulseleft = KeyDown(30)
	impulseright = KeyDown(32)

	mxspd#=-MouseXSpeed()*mousedampx
	myspd#=MouseYSpeed()*mousedampy

	TurnEntity camera,myspd,0,0

	;impulse
	If impulseforward vz#=vz+vzspd
	If impulseback vz=vz-vzspd
	If impulseleft vx#=vx-vxspd
	If impulseright vx=vx+vxspd
	


	;inertia and gravity
	vx=vx*inertia
	vy=vy/2
	vz=vz*inertia
	
	TurnEntity playerpivot,0,mxspd,0
	MoveEntity playerpivot,vx,vy,vz

	
	;stairclimbing
	oldx#=x#
	oldy#=y#
	oldz#=z#
	x#=EntityX(playerpivot)
	y#=EntityY(playerpivot)
	z#=EntityZ(playerpivot)


	pick=LinePick(x,y,z,0,-player_step,0,1)
	

	
	If pick
		slope# = 1.0-Abs(PickedNY()) *.025

		If EntityY(playerpivot)<PickedY()+player_step
			vy=vy+vyspd
		EndIf

	Else
		vy=vy-vyspd
	EndIf

	
	TranslateEntity playerpivot,0,vy,0


Return



KovaSteel(Posted 2003) [#4]
Thanks!i`ll try these methods!