FPS - example NEEDED BADLY
Blitz3D Forums/Blitz3D Beginners Area/FPS - example NEEDED BADLY
| ||
Enjoy my code below! |
| ||
Good question: dunno what happened there. I personally turned to FastExtend Libraries dll for realisticly looking water, but I believe there's also a free dll called something like "Ashadow" or so which does something similar. Dunno if this is the latest version though. http://andreyman.ucoz.ru/load/3-1-0-5 But if you are a bit patient, soon you'll be able to choose between either DX9 (Blitz Hardwired project) or the Blitz Irrlicht wrapper(bit different in structure, has a learning curve). And indeed many peeps are having a holiday. :-) This might be of use? http://jnoodle.com/Blitz3D_1/ for ladders: Blitz3D\Samples\Blitz 3D Samples\si\fps |
| ||
Hmm in hindsight, you're probably way beyond this, Nevermind, it's late here. |
| ||
It's starting to look like as usual I may have to plug on ahead with some of 'Tourist's old math formulae for riding objects minus the parent-child stuff, although I'd already had some success with the ladder as illustrated by Si's FPS (wish I'd studied it more carefully). It is interesting how much trouble just jumping can add to stuff! I want to post my basic engine for posterity once it has been completed. I will examine your links. Thank you. Edit: I've opted for yet another testbed collider system utilizing everything learned so far. I will upload the source right here for further discussion. |
| ||
That be cool. Perhaps people can help you better in that fashion or you may help someone else with it. |
| ||
This was my old buggy standard collider test bed. Please forgive how the colliders actually look. Heh. Type CamD Field Feet ;Camera parent object Field OldFoot ;We need it's position and orientation PRIOR to collisions Field Camera ;ACTUAL Camera - Man to be... (Head) Field Body ;Error discrepancy detector Field CCFeet ;Collision counts Field CCCam Field CCBod Field C$ ;What we're climbing Field P$ ;What we're a child of Field PIdx ;The parent index value Field DY# ;Delta Y (Y velocity for falling/gravity) Field OY# ;Offset Y (We must track this for carry catch) Field Pitch ;Camera Pitch tracker End Type Dim UC(1) Global Mde=0 ;0=Fork head snagger, 1=Overhead sticker (get stuck) Global Windowed=1,FirstFlag FirstPerson=0 ;Global B3 ;Global C Graphics3D 800,600,0,1-windowed ;Plane of existence ;ccc=LoadAnimMesh("Test.b3d") ;EntityType ccc,2 a=CreateCube() ;Ground ScaleMesh a,800,.01,800 PositionEntity a,0,-5,0 cp=CreateBrush(0,90,0) PaintEntity a,cp b1=CreateCube() b2=CreateCube() b3=CreateCube() b4=CreateCube() PositionEntity b1,-20,5,-15 PositionEntity b2,-20,5,15 ;We COULD get one ball pegged! -Fixed? ScaleMesh b1,.01,60,11 ScaleMesh b2,.01,60,11 ScaleMesh b3,20,1,20 ScaleMesh b4,40,8,40 PositionEntity b4,80,-4,120 cbr=CreateBrush(255,0,0) PaintEntity b1,cbr PaintEntity b2,cbr FreeBrush cbr ;(DELETED SECTION) NO PLANE-BASED WATER IS USABLE WITH A MESH-BASED TERRAIN MAP Global Cam.CamD = New CamD If FirstPerson Then Cam\Camera=CreateCamera() CameraRange cam\Camera,.1,5000 Else Cam\Camera=CreateSphere() ScaleMesh cam\Camera,8,8,8 c=CreateCamera() CameraRange c,.1,5000 PositionEntity c,-120,55,-60 PointEntity c,b1 End If Cam\Feet=CreateSphere() Cam\OldFoot=CreateSphere() Cam\Body=CreateSphere() l=CreateLight(1) PositionEntity l,0,5000,0 TurnEntity l,45,45,0 LightRange l,10000 ScaleMesh cam\Body,7,7,7 ScaleMesh cam\Feet,7,7,7 ScaleMesh cam\OldFoot,8,8,8 EntityRadius Cam\Feet,8 EntityRadius Cam\OldFoot,8 EntityRadius Cam\Body,7 EntityRadius Cam\Camera,7 PositionEntity Cam\Feet,-20,22,50 PositionEntity Cam\OldFoot,-20,22,50 TurnEntity Cam\Feet,0,90,0 PriorFootPos() MoveCamStuff() EntityType Cam\Body,1 EntityType Cam\Camera,1 EntityType Cam\Feet,1 ;EntityType Cam\OldFoot,1 EntityType a,2 EntityType b1,2 EntityType b2,2 EntityType b3,2 EntityType b4,2 Collisions 1,2,2,2 ;Type 1 to 2, Elips-Poly, Slide C=0 While Not KeyHit(1) If KeyHit(15) Or firstflag=0 Then Mde=1-Mde If Mde=0 Then RotateEntity b2,90,0,0 PositionEntity b2,-20,40.0122,-15 ;We get stuck on the lift side... ?? Else RotateEntity b2,0,0,0 PositionEntity b2,-20,5,15 End If End If PositionEntity b3,-20,-2+Abs(Sin(MilliSecs()*.1)*50),50 TurnEntity b4,0,1,0 CollisionHandling UpdateInput UpdateWorld RenderWorld Flip firstflag=1 Wend End Function UpdateInput() If Cam\CCCam Or Cam\CCBod Then ;Bounce Feet back to OldFoot GoPriorPos() End If ;Turn mxs=0:mys=0:mdr=0 ;U,D,R,L If KeyDown(201) Or KeyDown(73) Then mxs=-3 If KeyDown(209) Or KeyDown(81) Then mxs=3 If KeyDown(205) Or KeyDown(77) Then mys=-3 If KeyDown(203) Or KeyDown(75) Then mys=3 If KeyDown(82) Then PositionEntity Cam\Feet,-20,EntityY(Cam\PIdx,False),50,True End If TurnEntity Cam\Feet,0,mys,0 If EntityYaw(Cam\Feet)<0 Then TurnEntity Cam\Feet,0,360,0 If EntityYaw(Cam\Feet)>360 Then TurnEntity Cam\Feet,0,-360,0 RotateEntity Cam\Camera,EntityPitch(Cam\Camera)+mxs,EntityYaw(Cam\Feet),0 Cam\Pitch=Cam\Pitch+mxs If (Cam\Pitch)<0 Then Cam\Pitch=Cam\Pitch+360 If (Cam\Pitch)>360 Then Cam\Pitch=Cam\Pitch-360 ;Move If KeyDown(200)=True Or KeyDown(72)=True Then ;DebugLog Str(Int(EntityX(Cam\Body,True)))+","+Str((Int(EntityY(Cam\Body,True)-35)/2)-840)+"',"+Str(Int(EntityZ(Cam\Body,True))) mdr=10 ;Forward End If If KeyDown(208)=True Or KeyDown(80)=True Then ;DebugLog Str(Int(EntityX(Cam\Body,True)))+","+Str(Int(EntityY(Cam\Body,True)-35))+","+Str(Int(EntityZ(Cam\Body,True))) mdr=-10 ;Backward End If ;Gravity If cam\c$<>"" Then cam\DY#=230 ;Climbing If cam\c$="STOP" Then cam\DY#=194 ;Stop climbing - HOLD ALTITUDE If cam\c$="STOP" Then cam\c$="" ;Allow fall cam\DY#=cam\DY#-14:If cam\DY#<90 Then cam\DY#=90 ;Fall velocity increase ;Jump If KeyHit(57) Then ;Jump 310=up, 90=dn cam\c$="" UniqueCollisions(Cam\Feet):If UC(0)=1 And CountCollisions(Cam\Camera)=0 Then ;Are we sitting on the ground? Nothing above us? If cam\DY#=90 Then cam\DY#=310 ;Point accelleration angle/veloc full downward? End If End If S#=-Sin(cam\DY#)*10 If Cam\PIdx<>0 Then ;Part of my original engine... ;If OIdx.ObjD(Cam\PIdx)\DY#>0 Then ;We are going UP, so don't drop through floor S#=0 ; TFormPoint 0,0,0,Cam\PIdx,0 ; OY#=TFormedY() ; PositionEntity Cam\Feet,EntityX(Cam\Feet,True),EntityY(Cam\PIdx,True),EntityZ(Cam\Feet,True),False ; MoveCamStuff ;End If End If ;Jumping in progress... TranslateEntity Cam\Feet,-Sin(EntityYaw(Cam\Feet))*mdr,S#,Cos(EntityYaw(Cam\Feet))*mdr MoveCamStuff If CountCollisions(Cam\Feet)=1 Then ;Feet not touching anything else??? If Cam\CCCam Then ResetEntity Cam\Camera If Cam\CCBod Then ResetEntity Cam\Body End If PriorFootPos() ;Record our position prior to moving next time to avoid seeing through stuff End Function Function CollisionHandling() Cam\CCBod=CountCollisions(Cam\Body) Cam\CCCam=CountCollisions(Cam\Camera) If Cam\CCBod Or Cam\CCCam Then cam\DY#=90 ;Go back down ;Feet is good for telling what we've touched - Hands are actually only for ladders ;n=CountCollisions(Cam\Feet) ;If n=0 Then ; EntityParent cam\feet,0,True ; cam\PIdx=0 ;End If If n=1 Then UniqueCollisions(Cam\Feet):n=UC(0) k=GetParent(cam\Feet) For t=1 To n ;Order response to collider names by priority below i=UC(t) If t=1 Then ;Standing on If k<>i And k=b3 Or k=b4 Then ;Must be moving object to carry us DebugLog "MOVER" EntityParent Cam\Feet,i,True ;Be carried by it cam\PIdx=i Else If k<>i Then ;Standing on NON-MOVER DebugLog "NON-MOVER" EntityParent cam\feet,0,True cam\PIdx=0 End If End If End If Next End If End Function Function PriorFootPos() TFormPoint 0,0,0,Cam\Feet,0 OX#=TFormedX() OY#=TFormedY() OZ#=TFormedZ() PositionEntity Cam\OldFoot,OX#,OY#,OZ#,True ;RotateEntity Cam\OldFoot,EntityPitch(Cam\Feet,True),EntityYaw(Cam\Feet,True),EntityRoll(Cam\Feet,True) End Function Function GoPriorPos() TFormPoint 0,0,0,Cam\OldFoot,0 OX#=TFormedX() OY#=TFormedY() OZ#=TFormedZ() PositionEntity Cam\Feet,OX#,OY#,OZ#,True movecamstuff() ;RotateEntity Cam\Feet,EntityPitch(Cam\OldFoot,True),EntityYaw(Cam\OldFoot,True),EntityRoll(Cam\OldFoot,True) End Function Function MoveCamStuff() ;This looked like a global solution, apparently not... TFormPoint 0,20,0,Cam\OldFoot,0 OX#=TFormedX() OY#=TFormedY() OZ#=TFormedZ() PositionEntity Cam\Body,OX#,OY#,OZ#,True TFormPoint 0,30,0,Cam\OldFoot,0 OX#=TFormedX() OY#=TFormedY() OZ#=TFormedZ() PositionEntity Cam\Camera,OX#,OY#,OZ#,True RotateEntity cam\Camera,EntityPitch(Cam\Feet,True)+Cam\Pitch,EntityYaw(Cam\Feet,True),EntityRoll(Cam\Feet,True) If Floor(EntityPitch(cam\Camera)/90)=EntityPitch(cam\Camera)/90 Then TurnEntity cam\Camera,.5,0,0 ;Avoid camera gimbaling problems... ? End Function Function UniqueCollisions(entity) c=CountCollisions(entity) Dim UC(c+1) UC(0)=1 If c=1 Then uc(0)=2:uc(1)=CollisionEntity(entity,1):Goto UCXit For u=1 To c If u=<CountCollisions(entity) Then F=0:For t=1 To UC(0) If UC(t)=CollisionEntity(entity,u) Then F=1:Exit Next If F=0 Then UC(UC(0))=CollisionEntity(entity,t):UC(0)=UC(0)+1 Else c=u Exit End If Next .UCXit UC(0)=UC(0)-1 End Function Well, it's obviously utter rubbish, of course... He he... I just wanna make it work right! |
| ||
It seems as though dynamically created colliders as suggested by RemiD doesn't work unless you actually MOVE them, seems unusable. Linepick as suggested by RemiD leaves gaps of undetected convoluted geometry. He would then say "use a hidden, simplified set of geometry to test collisions" So... Assuming my geometry IS already pretty simple, what next? |
| ||
It seems as though dynamically created colliders as suggested by RemiD doesn't work unless you actually MOVE them, seems unusable. Linepick as suggested by RemiD leaves gaps of undetected convoluted geometry. I have not seen any major problem except on terrains as demonstrated here : http://blitzbasic.com/Community/posts.php?topic=101836 What may be a problem is if the movement speed of your entity is greater than the length of the pick or than the radius of the collider sphere "emitter", in this case the linepick may not detect the obstacle and the collider sphere "emitter" may go through the collider "receiver". So the solution is to decrease the movement speed of the entity or to increase the length of the linepick or to increase the radius of the collider sphere "emitter". Another thing to consider is that your colliders "receiver" must be welded or at least not have a gap between triangles. Sometimes when you model a mesh, it happens that it looks closed but in reality the vertices are not at the same position and this leaves a gap. This gap will provoke weird results with linepick. |
| ||
I will soon be posting a col_det based collider test bed that is really working well for me. It's temporary title: "House of Cards" (I make some HUGE assumptions, but it miraculously works) Thanks, RemiD! |
| ||
Here is my Col_Det-based collider test bed application for Tourist: Please tell me what you all think or how it might be improved. It seems to work pretty well, but there are issues with 'crusher' situations and sometimes getting stuck, and with moving objects, occasionally being pushed through the floor for some reason. It REQUIRES that all your scene objects be at 1,1,1 scale or 100% There are quite a few utillity subroutines (some convoluted) It's a jalopy, but it runs very nicely, I think. ;Collider Test Bed Application - a component of: ;"Tourist" Copyright (c) 2014 by Joseph D. Bockholt ;Free public domain license granted to those willing to ask permission for its use, ;and to include credit for parts of its inclusion in another application Include "D:\Program Files\Blitz3D\include\coldet.bb" Type CamD Field Camera ;ACTUAL Camera - Man to be... (Head) Field Body ;Collider Entity Field Col_Det ;ColDet pointer Field Idx ;Collider Idx Value (to avoid colliding with ourselves) Field C$ ;What we're climbing Field P$ ;What we're a child of Field PIdx ;The parent index value Field DY# ;Delta Y (Y velocity for falling/gravity) Field OX# ;OldX - Previous position used for col_det sliding Field OY# ;OldY - Previous position used for col_det sliding Field OZ# ;OldZ - Previous position used for col_det sliding Field Hooked ;No collision solution fall fix Field JumpPermission Field AbsGravity ;False means we can fall UP or SIDEWAYS from what we're standing on Field SMFallTime ;Brief, for GravityDetect - Really how long since no collider for axis flip Field LGFallTime ;For SFX, etc. End Type Type ObjD Field OrgName$ Field Entity ;Blitz Entity Field Parent ;Parent Entity Field Col_Det ;ColDet pointer Field OX#,OY#,OZ# ;Original coorinates Field X#,Y#,Z# ;Offset coordinates Field DX#,DY#,DZ# ;Delta values to change offsets with (DY is Needed for gravity negation) Field Xr#,Yr#,Zr# ;Offset Rotation values Field W#,H#,D# ;Bounding dimensions Field Rot# ;Primary intended use was for doors Field Mode% ;'Mode' the object is in Field ModeTim# ;Used for timing purposes End Type Const FirstPerson=0 Const GfxW=800,GfxH=600 Global Map Global OIdxCnt=0 Dim OIdx.ObjD(OIdxCnt) Dim OUC(1),UC(1) Global Windowed=1,FirstFlag Graphics3D GfxW,GfxH,0,1-windowed ;Plane of existence coldet_start() Global Cam.CamD = New CamD Cam\AbsGravity=True If FirstPerson Then Cam\Camera=CreateCamera() CameraRange cam\Camera,.1,5000 Else Cam\Camera=CreatePivot() c=CreateCamera() CameraRange c,.1,5000 End If Map=LoadAnimMesh("Test.b3d") AssignDataIndexes If Not FirstPerson Then TurnEntity c,30,0,0 PositionEntity c,EntityX(cam\Body,True),EntityY(cam\Camera,True)+40,EntityZ(Cam\Body,True)-110 EntityParent c,Cam\Body,True End If MoveEntity Cam\Body,0,20,0 l=CreateLight(1) PositionEntity l,0,5000,0 TurnEntity l,45,45,0 LightRange l,10000 ;dummychild=CreateSphere():ScaleMesh dummychild,10,10,10 ;i=fndchild("SpinnerChild") ;MoveEntity i,0,33,0 While Not KeyHit(1) ;i=fndchild("Lift") ;PositionEntity i,EntityX(i),-10+Abs(Sin(MilliSecs()*.1)*90),EntityZ(i) ;i=fndchild("Spinner") ;TurnEntity i,0,0,0 ;i=fndchild("SpinnerChild") ;RotateEntity i,0,0,Sin(MilliSecs()*.2)*45 UpdateWorld UpdateColDetWorld UpdateInput CollisionHandling RenderWorld Flip firstflag=1 Wend Unload Function UpdateInput() GrabCheck Cam\OX#=EntityX(Cam\Body) Cam\OY#=EntityY(Cam\Body) Cam\OZ#=EntityZ(Cam\Body) Cam\PIdx=GetParent(Cam\Body) ;Turn mxs=0:mys=0:mdr=0 ;PU,PD,R,L If KeyDown(201) Or KeyDown(73) Then mxs=-3 If KeyDown(209) Or KeyDown(81) Then mxs=3 If Int((EntityPitch(Cam\Camera)+mxs)/90)=(EntityPitch(Cam\Camera)+mxs)/90 Then mxs=mxs*2 ;Avoid camera gimbal problem If KeyDown(205) Or KeyDown(77) Then mys=-3 If KeyDown(203) Or KeyDown(75) Then mys=3 ;Rotations TurnEntity Cam\Body,0,mys,0 If EntityYaw(Cam\Body)<0 Then TurnEntity Cam\Body,0,360,0 If EntityYaw(Cam\Body)>360 Then TurnEntity Cam\Body,0,-360,0 TurnEntity Cam\Camera,mxs,0,0 If EntityPitch(Cam\Camera)<0 Then TurnEntity Cam\Camera,360,0,0 If EntityPitch(Cam\Camera)>360 Then TurnEntity Cam\Camera,-360,0,0 ;Tab key If KeyHit(15) Or firstflag=0 Then End If ;Move If KeyDown(200)=True Or KeyDown(72)=True Then ;DebugLog Str(Int(EntityX(Cam\Body,True)))+","+Str((Int(EntityY(Cam\Body,True)+50)/2)-840)+"',"+Str(Int(EntityZ(Cam\Body,True))) mdr=10 ;Forward End If If KeyDown(208)=True Or KeyDown(80)=True Then ;DebugLog Str(Int(EntityX(Cam\Body,True)))+","+Str(Int(EntityY(Cam\Body,True)+50))+","+Str(Int(EntityZ(Cam\Body,True))) mdr=-10 ;Backward End If ;Gravity If cam\c$<>"" Then cam\DY#=230 ;Climbing If cam\c$="STOP" Then cam\DY#=194 ;Stop climbing - HOLD ALTITUDE If cam\c$="STOP" Then cam\c$="" ;Allow fall cam\DY#=cam\DY#-14:If cam\DY#<90 Then cam\DY#=90 ;Fall velocity increase S#=-Sin(cam\DY#)*10 ;Jumping/gravity ALWAYS in progress... TranslateEntity Cam\Body,-Sin(EntityYaw(Cam\Body))*mdr,S#,Cos(EntityYaw(Cam\Body))*mdr,Cam\AbsGravity UpdateCam CollisionHandling ;Jump If KeyHit(57) Then ;Jump 310=up, 90=dn cam\c$="":EntityParent Cam\Body,0,True:Cam\PIdx=0 If Cam\JumpPermission Then ;Are we sitting on the ground or touching something? - Permission required prior to CollisionHandling If cam\DY#=90 Then cam\DY#=310 ;Is angle/veloc full downward? End If End If If Not Cam\JumpPermission Then cam\DY#=90 End Function Function GrabCheck() ;Grab Object If MouseDown(1) Or KeyDown(82) Then p=CameraPick(Cam\Camera,MouseX(),MouseY()) If p<>0 Then Bob=CreatePivot() PositionEntity Bob,PickedX(),PickedY(),PickedZ() D=EntityDistance(Bob,Cam\Camera) If D<80 Then DebugLog Mid$(EntityName$(p),5) FreeEntity Bob End If End If End Function Function CollisionHandling() Cam\Hooked=0 Cam\JumpPermission=0 CollisionDetect If UC(0)>0 Then ;Assume Y gravity negation 1st Cam\SMFallTime=0 ;Reset gravity detectors (We're on something) Cam\LGFallTime=0 ;ASSUMPTION: IF WE MOVED... (vs having gotten HIT by something) OX#=Cam\OX# OY#=Cam\OY# OZ#=Cam\OZ# X#=EntityX(Cam\Body) Y#=EntityY(Cam\Body) Z#=EntityZ(Cam\Body) ;Back us out vertically carefully against our primary collider If Y#>OY# Then Q#=Y#:Y#=OY#:OY#=Q# ;Swap Y,OY PositionEntity Cam\Body,X#,Y#,Z# idx=0:For t#=Y# To OY#+11 Step .1 ;Step height of 10 (1' scale for me) ;PositionEntity Cam\Body,X#,T#,Z# TranslateEntity Cam\Body,0,.1,0,Cam\AbsGravity f=0:For u=1 To UC(0) c=ChkCamCol(OIdx.ObjD(UC(u))\Entity) f=f+c:If c=1 Then idx=UC(u) ;(Last highest collider) Next If f=0 Then Y#=T#:Exit ;Sucess? Next ;DebugLog Str(UC(0))+","+OIdx.ObjD(idx)\OrgName$ UpdateCam If UC(0)=0 Then ;Success If idx<>0 Then I$=OIdx.ObjD(idx)\OrgName$ If OIdx.ObjD(idx)\Entity<>GetParent(Cam\Body) Then FixRoll EntityParent Cam\Body,OIdx.ObjD(idx)\Entity,True ;* SEE BOTTOM OF CODE Cam\PIdx=idx End If End If Goto XitC End If ;OTHERWISE, Not a foot collision... PositionEntity Cam\Body,OX#,OY#,Z#:UpdateCam ;Z slide test If UC(0)=0 Then Goto XitC PositionEntity Cam\Body,X#,OY#,OZ#:UpdateCam ;X slide test If UC(0)=0 Then Goto XitC PositionEntity Cam\Body,OX#,OY#,OZ# ;No solution, simply revert. Cam\Hooked=1 UpdateCam Else tt=MilliSecs()/1000 If Cam\SMFallTime=0 Then ;Begin timing Cam\SMFallTime=tt Cam\LGFallTime=tt Else ;If time is up, De-Parent us, and flip us right-side-up If Abs(tt-Cam\SMFallTime)>.01 Then EntityParent Cam\Body,0,True RotateEntity Cam\Body,0,EntityYaw(Cam\Camera,True),0,True ;Sneaky- Borrow child's Yaw End If If Abs(tt-Cam\LGFallTime)>4 Then ;Fallsound and message here cam\LGFallTime=0 End If End If End If .XitC ;DebugLog Str(RatY()) TranslateEntity Cam\Body,0,15,0,Cam\AbsGravity:UpdateCam If UC(0)=0 Then Cam\JumpPermission=1 TranslateEntity Cam\Body,0,-15,0,Cam\AbsGravity End Function Function FixRoll() j=GetParent(Cam\Body) If validentity(j) Then i=GetIdxFromName(EntityName$(j)) If OIdx.ObjD(i)\Xr#<>0 Or OIdx.ObjD(i)\Zr#<>0 Then RotateEntity Cam\Body,0,EntityYaw(Cam\Camera,True),0,True ;Sneaky- Borrow child's Yaw RotateEntity Cam\Camera,0,EntityYaw(Cam\Body,True),0,True ;Sneaky also End If End If End Function Function RatY#() ;Our RATIONAL Y position A#=Int(EntityY#(cam\Body,True)*100) A#=Int(A#)*.01 Return A# End Function Function CollisionDetect() UC(0)=1 For t=1 To OIdxCnt If t<>Cam\Idx ;Not ourselves If OIdx.ObjD(t)\Col_Det<>0 Then ;Object must be a mesh... If coldet_collision (Cam\Col_Det,OIdx.ObjD(t)\Col_Det) Then UC(UC(0))=t:UC(0)=UC(0)+1 End If End If End If Next UC(0)=UC(0)-1 End Function Function CollisionTest(Idx) f=0 If Idx<>Cam\Idx ;Not ourselves If OIdx.ObjD(Idx)\Col_Det<>0 Then ;Object must be a mesh... If coldet_collision (Cam\Col_Det,OIdx.ObjD(Idx)\Col_Det) Then f=1 End If End If Return f End Function Function FndChild(nm$) ;Find by name is stupid because 'Chair' is EVERYWHERE - works for now f=0:For t=1 To OIdxCnt If nm$=OIdx.ObjD(t)\OrgName$ Then f=OIdx.ObjD(t)\Entity:Exit Next Return f End Function ; Cycle through all relevant submeshes (9 levels deep only) Function AssignDataIndexes() ;file=ReadFile("D:\Documents and Settings\Joseph D. Bockholt\Desktop\Tourist\X-Files\CandylandArcadeBldg.dat") ;n=Int(ReadLine(file))+10 ;CloseFile(file) n=30 Dim OIdx.ObjD(n):For t=1 To n:OIdx.ObjD(t) = New ObjD:Next Dim UC(n),OUC(n) ;Whilst colliding with everything is improbable... OIdxCnt=1 For t0=1 To CountChildren(Map) entity1=GetChild(Map,t0) x$=EntityName$(entity1):IdxName entity1,x$ For t1=1 To CountChildren(entity1) entity2=GetChild(entity1,t1) x$=EntityName$(entity2):IdxName entity2,x$ For t2=1 To CountChildren(entity2) entity3=GetChild(entity2,t2) x$=EntityName$(entity3):IdxName entity3,x$ For t3=1 To CountChildren(entity3) entity4=GetChild(entity3,t3) x$=EntityName$(entity4):IdxName entity4,x$ For t4=1 To CountChildren(entity4) entity5=GetChild(entity4,t4) x$=EntityName$(entity5):IdxName entity5,x$ For t5=1 To CountChildren(entity5) entity6=GetChild(entity5,t5) x$=EntityName$(entity6):IdxName entity6,x$ For t6=1 To CountChildren(entity6) entity7=GetChild(entity6,t6) x$=EntityName$(entity7):IdxName entity7,x$ For t7=1 To CountChildren(entity7) entity8=GetChild(entity7,t7) x$=EntityName$(entity8):IdxName entity8,x$ For t8=1 To CountChildren(entity8) entity9=GetChild(entity8,t8) x$=EntityName$(entity9):IdxName entity9,x$ Next:Next:Next:Next:Next:Next:Next:Next:Next OIdxCnt=OIdxCnt-1 End Function Function UpdateCam() coldet_setmatrix(Cam\Body,Cam\Col_Det) CollisionDetect End Function Function UpdateCamMat() coldet_setmatrix(Cam\Body,Cam\Col_Det) End Function Function ChkCamCol(e) f=0 a=GetIdxFromName(EntityName$(e)) coldet_setmatrix(Cam\Body,Cam\Col_Det) coldet_setmatrix(e,OIdx.ObjD(a)\Col_Det) If coldet_collision (Cam\Col_Det,OIdx.ObjD(a)\Col_Det) Then f=1 Return f End Function Function ChkCol(e1,e2) f=0 a1=GetIdxFromName(EntityName$(e1)) a2=GetIdxFromName(EntityName$(e2)) coldet_setmatrix(e1,OIdx.ObjD(a1)\Col_Det) coldet_setmatrix(e2,OIdx.ObjD(a2)\Col_Det) If coldet_collision (OIdx.ObjD(a1)\Col_Det,OIdx.ObjD(a2)\Col_Det) Then f=1 Return f End Function Function GetIdxFromName(a$) Return Floor(Left$(A$,4)) End Function Function UpdateColDetWorld() dummychildentity=CreatePivot() For t=1 To OIdxCnt i=OIdx.ObjD(t)\entity If ValidEntity(i) Then ;(Anti MAV) If OIdx.ObjD(t)\Parent<>0 Then PositionEntity dummychildentity,EntityX(i,True),EntityY(i,True),EntityZ(i,True) RotateEntity dummychildentity,EntityPitch(i,True),EntityYaw(i,True),EntityRoll(i,True) OIdx.ObjD(t)\Xr#=EntityPitch(i,True) OIdx.ObjD(t)\Yr#=EntityYaw(i,True) OIdx.ObjD(t)\zr#=EntityRoll(i,True) coldet_setmatrix(dummychildentity,OIdx.ObjD(t)\Col_Det) Else coldet_setmatrix(i,OIdx.ObjD(t)\Col_Det) End If End If Next FreeEntity dummychild End Function Function ValidEntity(e) ;Exclusions to prevent MAVs f=0 If e<>0 Then i=GetIdxFromName(EntityName$(e)) a$=Mid$(EntityName$(e),5) If Len(EntityName$(e))>4 And e<>Cam\Camera And EntityClass$(e)="Mesh" And EntityName$(e)<>"Scene Root" And a$<>"Unknown" And Left$(a$,6)<>"B3DEXT" And a$<>"Player1" And a$<>"Camera" Then f=1 End If Return f End Function Function IdxName(e,a$) If Trim(a$)="" Then a$="Unknown" b$=Str(OIdxCnt) While Len(b$)<4 b$="0"+b$ Wend b$=b$+a$ OIdx.ObjD(OIdxCnt)\OrgName$=EntityName$(e) OIdx.ObjD(OIdxCnt)\Entity=e OIdx.ObjD(OIdxCnt)\Parent=GetParent(e) OIdx.ObjD(OIdxCnt)\OX#=EntityX(e) OIdx.ObjD(OIdxCnt)\OY#=EntityY(e) OIdx.ObjD(OIdxCnt)\OZ#=EntityZ(e) OIdx.ObjD(OIdxCnt)\Col_Det=0 ;Find object bounding box :( If EntityClass$(e)="Mesh" Then OIdx.ObjD(OIdxCnt)\W#=MeshWidth#(e) OIdx.ObjD(OIdxCnt)\H#=MeshHeight#(e) OIdx.ObjD(OIdxCnt)\D#=MeshDepth#(e) OIdx.ObjD(OIdxCnt)\Col_Det=coldet_make(e,1) EntityPickMode e,2,2 End If If a$="Camera" Then PositionEntity Cam\Camera,EntityX(e),EntityY(e),EntityZ(e) EntityPickMode e,0 End If If a$="Player1" Then Cam\Body=e EntityParent Cam\Camera,e Cam\Col_Det=OIdx.ObjD(OIdxCnt)\Col_Det Cam\Idx=OIdxCnt EntityPickMode e,0 End If NameEntity e,b$ OIdxCnt=OIdxCnt+1 End Function Function Unload() ;<--------------------KEEP FILLING THIS IN ;FreeEntity ... For t=1 To OIdxCnt coldet_free_model(OIdx.ObjD(t)\Col_Det) Next coldet_end() ;FreeFont fnt ClearWorld EndGraphics End End Function ;* This simple solution for ANY moving objects REQUIRES ALL OBJECTS in the .b3d file: ; MUST have 1,1,1 scale ONLY prior to export and should REMAIN at 1,1,1 scale FOREVER ; PROBABLY SHOULD have been originally exported with 0,0,0 rotation TO START WITH -- ; ESPECIALLY if they have a PARENT! ; WE DO NOT CARE if objects have a parent, or are NOT at 0,0,0 xyz position. ; Child objects may be problematic to track collisions with... |
| ||
Additional: The .b3d file should have a Camera object at x,y+50,z xyz being wherever you want. The Player1 box has its pivot at the bottom center, and has dimensions of: 15x53x15 My scene file was exported from max5 via the blitz pipeline. I have not uploaded it. (If you wanted to know) |
| ||
How am i supposed to test your code if i don't have the required files ? If you don't want to share the map of your game, at least provide a simpler (but similar) map, so that we can test. Thanks, |
| ||
Sick of this problem... HERE!;HEXREAD o=0:fl=0:ck%=0:pre_ck%=0:mck%=0 MyPath$=".\" NM$="PasteMe.Hex" FileIn=ReadFile(NM$) NM$=ReadLine(FileIn) FileOut=WriteFile(MyPath$+NM$) ck%=ReadLine(FileIn) While Not Eof(FileIn) ReadIn$=ReadLine(FileIn) If ReadIn$<>"" Then o=0:For t=1 To Len(ReadIn$) Step 2 Nib1$=Mid$(ReadIn$,t+0,1) Nib2$=Mid$(ReadIn$,t+1,1) N1=Instr("0123456789ABCDEF",Nib1$)-1 N2=Instr("0123456789ABCDEF",Nib2$)-1 Byt=(N1*16)+N2 pre_ck%=pre_ck%+(Byt*(256^o)) ;Build 8 byte value o=o+1:If o>3 Then o=0:mck%=mck%+pre_ck%:pre_ck%=0 ;Checksumming WriteByte(FileOut,Byt) Next End If Wend CloseFile(FileOut) CloseFile(FileIn) If mck%<>ck% Then RuntimeError "Warning: Checksums did not match!" End ;HEXWRITE fl=0:mck%=0:pre_ck%=0 NM$="BlitzLevel.Zip":pc=0 FZ=FileSize(NM$) FileIn=ReadFile(NM$) While Not Eof(FileIn) ReadIn=ReadInt(FileIn) pk=pk+1:If pk<4 Then Print Hex(ck%) A$=Hex(ReadIn) o=0:For t=Len(A$)-1 To 1 Step -2 Nib1$=Mid$(A$,t+0,1) Nib2$=Mid$(A$,t+1,1) N1=Instr("0123456789ABCDEF",Nib1$)-1 N2=Instr("0123456789ABCDEF",Nib2$)-1 Byt=(N1*16)+N2 pre_ck%=pre_ck%+(Byt*(256^o)) ;Build 8 byte value o=o+1:If o>3 Then o=0:mck%=mck%+pre_ck%:pre_ck%=0:pc=pc+1 ;Checksumming Next Wend CloseFile(FileIn) o=1 FileIn=ReadFile(NM$) FileOut=WriteFile("PasteMe.Hex") WriteLine(FileOut,NM$) WriteLine(FileOut,mck%) While Not Eof(FileIn) ReadIn=ReadInt(FileIn) A$=Hex(ReadIn) b=Asc(Mid$(A$,7,1)):WriteByte(FileOut,b) b=Asc(Mid$(A$,8,1)):WriteByte(FileOut,b):fl=fl+1:If fl=FZ Then Exit b=Asc(Mid$(A$,5,1)):WriteByte(FileOut,b) b=Asc(Mid$(A$,6,1)):WriteByte(FileOut,b):fl=fl+1:If fl=FZ Then Exit b=Asc(Mid$(A$,3,1)):WriteByte(FileOut,b) b=Asc(Mid$(A$,4,1)):WriteByte(FileOut,b):fl=fl+1:If fl=FZ Then Exit b=Asc(Mid$(A$,1,1)):WriteByte(FileOut,b) b=Asc(Mid$(A$,2,1)):WriteByte(FileOut,b):fl=fl+1:If fl=FZ Then Exit o=o+8:If o>80 Then o=1:WriteByte(FileOut,13):WriteByte(FileOut,10) Wend CloseFile(FileIn) CloseFile(FileOut) End ------- Paste from below here to a notepad file: "PasteMe.Hex" --------- BlitzLevel.Zip -940504097 504B03041400000008009958284420A052E0A30D00006363000008000000746573742E623364EC9A 756C535114C61FEEEE9A11DCA12D0E2B7D45835320380C5A74D828090992874B8020C33D40084E5B 860559B701C1FE40822468701BC125D8B9E36C1768DF390FFA074BE025278F3E7EFBBE7BBE7B398C C754D5DCA4477F4549A3284AA7A65D1D0A5C6AC7CE8E16E9142533FCBA9FD9D92F6ACCE841CACA15 45ADA21EDD7359154583125FF4FDFACA5C2922DBB66E0DBF7BEB5623AFA7E69F8BCC9B9BC30A220D 9F3E1C14FEC7220B17E4B186BC927BB723AC9EDDBBC34F9F68FE9745664CCF68BD75ED5AF8244D69 F47733496E05DAFA6D11873B62B83322CA392CC2ED8A1A1C1199B4D57760AB9F84B2D5EF5FBBC345 3E09B1B10DFF5844042B6AD6CCCCBFDD56DB764D9ABEEBA3288EFEAEE1AEB08E2346B8959F2F2127 4B3C482EF1A55BD32B4AB3C81123A2909E5FF74C8389B503BF4A5E6D9A3A5AB8D37F5F58978E9D1C 67D27D5F6C5AAC447BC904C1452FBC152F57107801D7C41027F5ECAC1E72BC5E98FF07DFA37A7A3C 27F5D057E3F490433D3E171D167D794EFAF27A0C1798B3CC5823FB408ECF85E702F4B8F3826781EA 83E130175E8FE102F74DE6AB917D20C79F679EE3F43A756CE988C65FA7C37BDAE4CF38983241A587 CA20EEF839235456A82C5099C51D3F6783CA0995032ABBB8E3E75C5079A1F240E51677FC9C0FAA20 5401A8FCE28E9F0B418989B50B0CDB8F891A19E90A53478C556AAF5C132FC656B3357DEDA18CADDE 45E7C72978D73BFAF8FBAA214EEAA906F5544E6F5EF92BEA0FBE563DBD209C46E8095FCD809E4AFB CAFCA8F1813A3C87BE2C27FB30EE8B3DB0FB81D9F1B9483DB20FC969942F353E64CE3C87BE0C27FB 30EC8BF972E780E3D0D718277D35ACC0B185E3299D1C5970C9679992471656467C9632B6B0B2E1B3 94B185950B9FA58C2DAC7CF82C656C611512CF706CED00C38E2E67987D4C3F9772D0B2DE2E86D6A1 1693E2431C5A7E05EFCCF0B019E4FC92A7F50C72FEDE4573ABE2CE0C0F5B104E23F484AF46EA2147 FBCAFC98E161E339E9CB72B20FE3BED803BB1F981D9F8BD423FB909C46F932C3C3CF7332179E937D 18F6C57CB973C071E86B94B319195A6953E9D0DA228656C4B0914AC5B3D9930656D64FEB43FA2EEB F08C4B714F069A453871F5F6C686CFAF32EC68B937577DBF06E338D0D73EC7F14E155C5DE4EEEE9C 12C01D04BDC7A0D70BC24ED61B3FFC7E00D719F4E6829EE092F5EA55981FC0755D7327EE62B90DB1 E87B04B8A07F483256EB6ECF75228DBD8FE883E0A49E581FAF87EBD3E17ECEAFE8AA539E319F0678 C501A3F2BBBBA391A5C4A8477B0447F5316170038BEDC27DE4F473F14567F1B66B9C8FF57D72AC9A 754DCE0656FFAD775E6A3F4E017718B8572712F650B99C05EE20700F5BC6ECA1FA48046E2570F058 A37C07C6AA26C771FB2EC0ACD4B97A08F99586FC0447ED6FE562F52D9B8FDC454EBF8FEDD1594CBD 1BE73371BEC78E553BEACFD9E0E874CB7213750EAE02B713B8F5D6D1166ADF2E03E7012E6791BE14 A7C603170F1C35B0D2A5D281E501C316AE086798635844FFA1AE286561ED2AFEF77912D42396F6FE 5006D7DBB03D7162AA6B3D9B6C167CD5A1D53605DB40E05496937A36E0CAF37AC8F17A4907427C5E E2BCE303EE68503DC969D1FA5C5C1FF0ED837A04A7F25C607E9221F3D390D3E83EA41E958B715F99 2FBD1F92A372A139EC43721AEF0B17B0D1CEFE66E65C69825B041CB7BF04A70670ACAFCC983C073C 87B9488EEE837FAB953EB50F2E357244CAE0BA32AEB73AE0CE2EF5FFE0FA3FB8FE0FAE7F7B706548 A583CB05068E9183870F879995CB7632E95DFCF88F63437AAD55FCE49E38C17D78BA963CFBC0A986 38A9A71AD45339BD44537E9BF09D763C43D25CAB74EF4CCD607A827B0FDCAB3C0B74B912A0F70C38 F4D5045759472F99EBDBAB38E12BF33BD8B5BAD91D7DDF84BD90F9798AF5AA2538AA8FF9E90FD7C8 F5A03372FAB9DC685CCB2C9EB1BE7836F8FD903386CA85D3C33E8CFBE2853C7DAE70EF88FDE5F4B0 0FE3BE22DF2F6F3BC574ECD6D44770D48C91FB86DCE056697D95C7BDD84DF601DC9E62BD62AADC6B EDD39B591953E9CCF28021CE2CFBA0C1914EE5F9FBC2F6E15BCADB6FCECE19D2EBAD991D3EFA7BC6 548A9F0C776A800067E339A9371B785E8FE766805E95A852F153E04EBD179F053A829B0A1CF53E7E 3AEA812EF93E7E36EA893BE1FB537E6B3A3CF3EE3F350A5F4791F969AB8A5D474EBF8FC444BB2767 C279E4F47339F220AD6F55B15EBC2FF47000D627D649EE0770627D642EC889F53D8575527D086E0D AC4FAC93F2ADF3D9E373D61A6B163C73AEB4988B656B098EDADF6AAFF27AFB7628889C7E1FAB7A24 F8ECCB2A56647D21DF1C09E72DEB3A3C3351E74070B01F16F23C2377F0D428CBF3447B4DAA0FC1AD 2C76DD72F4415AB3DEE0CA944A07D716306C3D78805B59EE7894F43E7E61B6B721FDEBF013FECD7F 37FD42F23B28E054439CD4530DEAA99C5ED749371AFFE06BD5D30BC269849EF0D50CE8A9846F607E D80B9B1F726C1FC8F1B9F0BEB207663F303B3E17A947F621398D3D0798359133CBA12FC3C93E0CFB 62BEDC39E038F435CA19FAA987CCA9746079C0B009FC746958D3B1F0DF88912EA5B8FBA64D49532A 7CE3FB69B65006578DDE93FDBDD33C0F6F3BF742ECCDD55A3911D2DA9D5B03FE260E7B3E28854B7E 2DB3EE570EF55A03B7ADD006DB397742053DBD52A027B8EDC0BD1C7208B9E07A8A32526D07BED400 81F505E3343D3DE18B7D907A82237C657EE8BB624516AFE885CB4F72741FCB91A37231EEAB5927AE 6EE1CD5AF3BA89DA0FC1AD5831CBBB655F2133990B7091D5177B168D2F63A2FB90838BF25DB0747E 4CDDEC997C82A7CE95A9D3A218E81739FDFDB557D8E51DBAACF46EE4883EF0627C65BEF4396038CC 85E5E4FA90A3065796543AB8BE316FC62A4E4461189DA4B4B3B15E0B1B53E98A85853AC92E4C2388 6C612729B6105C08B1129B3CC074BEC0943E406AC12E0F60B92F20284C6767BC2E0716F6E7EEB917 B75008CBEAF1FB6E8E5FC69D40EEA6E297EF961F4ED70F9ACF9F6E5F5CDC1F7EFBFE2FD7ACF46BE4 35CED7ACC7F1B973FC39BCE63947DEC99C5C7695C98BDC269747EF46F2E0B2BDD11FCF45FDC1E9F3 80132F65BD3C07FDF7C09D79913C387A39A0EE00D779CFCED12B1CE7ABE9C5AFEE00CEF7EC1CBDFA C3D6ADFFF49A7596BE2E9667A7EB2587EA2EEF5D78FCDEEFBFECD323FDE6B3497AFCFD6B8FD337F3 C3A3E3D7276F16ED8BE3576DFAFED1BCF403441F674D933E5AF576FDBE99FDFA79F17FD28F2787FA F6FFD1ECF23AD9DFBB7A9D3CE05DA7DDB5EF8E25AE558E3CB856F3E0342FB1F4A2289317B94D2E8F DE8DE4C1E57BA770E225391F032779ADE6C179DE60FEC81BD41F79EA8F3CF5D7C0F9AEBA7911177A 35AFF5BCD1FC9137AA3FF2D41F7970DEEB5EFAC069AFE7157A3E98BBBF1ECEFC91873FC983F35EF7 B20D9CF77A5E99E7CEFC91D7A93FF2D41F79EA6F02E7D7BFF3322EF46A5EEB792BF347DE4AFD91A7 FEC883F35EDFD5741138EBF5BC42CFBDF923AF577FE4A93FF2DC1F9C7BB953C6855ECD6B3D6F307F E40DEA8F3CF5471E9CF7BA97FB81D35ECF2BF4BC357FE46DD51F79EA8F3C38EF752F4F03A7BD9E57 E87967FEC8DBA93FF2D41F79EA2FDE7FF05C22D79673E9E1DCD7C0496F780E99FB99E02E735FE179 9C0F8E4CB98FC275D6B373F40AC7F96A7AF16B3B308EDE52EEDA4F854D752FF1FECDB9C1387A87AA DEE83772B63FCEA7FB83B3FDC1F90EF05CC80DCA71BECA5EFCCA7DBC734329A7FB6B742FF1FED7B9 D1387AE1BC57F707A7FBE37CBA3F38DB1F9CEF00CF85DCA81CE7ABEA0D7E333B706E2CE5647F357B E9858BF7D3BE2B38EFD5FDC1F9FE389FEE0F4EF60777837BC18B729CAFA617BFFA7A138EDE324EF6 57B1976D05D715EEAA2BEED5FDC1D9FE389FEF0FCEF7B7BDD1BDE04539CE57D58B5F7DBD39D79572 BABF89EF05EEBC825B19472F9CF7EAFEE0747F9C4FF70767FB83F31DE05939BC28C7F9AA7A83DFCC 0E9C5B9572BA3FDF4B7CFFCFB9FE2AF787953B366120088220988582F8203E5605A10025A35D51F3 707EC30E47D9F7C7559DEFD25F1DFDB58FFEEAE0AFEEA097DE855DFBD6BBF2576757ED5B3BFB9BBD BC1E746F75DDADF35DFAABA3BFF6D15F1DFCD52D0E462FBD0BBBF6AD77E5AFCEAEDAB776F4B77BB9 1E749FD1559DEFD25F1DFDB5CFFEEAECEF3AEAA57761D7BEF5AEFCD5D955FBD68EFE762FF7DCFD9A D1559DEFD25F1DFDB5CFFEEAECEF3EEAA57761D7BEF5AEFDD5D955FBF68EBF927D29B56BDD040000 00A2539376A92C75D7DFA9BBBBBBBBBB1B0E0B1FCA911C09616378CB7DC3250BD28F5AFE9F5B37BA D0A91E5B3FFAD0AB01DB308630A811DB38C630AA095BE69B2B5491AD24E7A32BB64D630A939AB1CD 630EB35AB02D63098B5AB1AD630DABDAB065BEBC5295D92A90FDE995DBB6B1854DEDD8F6B1875D1D D88E7184439DD8CE7186535DD86A508D4A55D91A50875AD5DBAE71854BDDD8EE71875B3DD89EF184 47BDD8DEF186577DD85AD08C4635D93AD08656B5DBBEF1854FFDD8FEF1875F056C61841054C41647 0C51256CA916E4D94002000080603B6FDB365A7CDBB66DDBFE630BB7C106934C221210A7782F15C9 48528AD78176B4A9D3EB4137BAD4EB0DA01F7D1AF446308C218D7A99C8409AD2BD5C64234B39DE04 C631A6496F06D398D2ACB78079CC69D15BC13296B4EA15A20079CAF74A518C2295781B58C79A36BD 1D6C634BBBDE01F6B1A743EF04C738D2A957890A94A9DCAB4535AA54E35DE01C67BAF46E708D2BDD 7A0FB8C79D1EBD173CE349AF5E231A50A77AAF15CD68528BF78177BCE9D3FBC137BEF4EB05F08F3F 05BD08C20829EAC500504B010214001400000008009958284420A052E0A30D000063630000080000 000000000000002020000000000000746573742E623364504B0506000000000100010036000000C9 0D00000000 |
| ||
Why not post a link to a 7z or zip archive, with the code example and all the required files included and ready to run. It will be easier and faster for us to test don't you think ? |
| ||
Sure except my system is not permitted such access and is text only. I provide these files as a courtesy. Sorry for any inconvenience this may cause. Unless I state otherwise, these programs (minus any credit for modules developed by others on this site) are public domain. You can add them (whole zip file) to codearc if you like. |
| ||
I have tried your example. It seems to work ok, except i have noticed a big slowdown when there is a collision between the character collider and another collider. Have you tried to use this system to detect a collision between moving characters and then reposition them ? |
| ||
Oops! Sorry I don't presently handle more than 1 player. I haven't tried comparisons between other moving objects. It may be a bit of a cycle waster. I anticipate an improvement when I reach the bumper cars module and fix whatever is wrong with this module. Bit of a wait. I don't do that yet. Tourist is much less active a FP(S) ap than most. I've also been smashing bugs left and right on it, so be aware that they exist... If anybody discovers how to fix the lift/crusher priority problem, let me know. |