Colliders - Rephrased
Blitz3D Forums/Blitz3D Beginners Area/Colliders - Rephrased
| ||
Perhaps I've been asking the wrong questions: Part 1:I MUST use standard collision detection; When the slide runs amock and reports that I'm elsewhere when I can see the sphere (as rendered) is in the same spot (or somewhere else), how do I obtain it's REAL entityXYZ? Since true or false both report the same thing. I do have two other ellipse pivots (not children) that I could compare with. Is there some tform thingy for ACTUAL position? Part 2: Once we've figured that out, I need to snap off slide so I can put it where it's supposed to be and snap it back on again without multiple updateworlds. ? (Lots of polygons from loadanimmesh) I'm hoping to come back tomorrow and be able to continue my work. |
| ||
RemiD mentioned destroying and recreating them to move them- Have you all found this to be effective? |
| ||
If you want to reposition a collider, you need to either : remove it from the collisions calculation for at least 1 frame, in this case ResetEntity() can help or delete the collider and recreate one with the desired orientation/position I have found that in some cases ResetEntity does not work properly (see : http://www.blitzbasic.com/Community/posts.php?topic=98459 ) |
| ||
Excellent work, Remi! I have a test bed application also. If collisions are so difficult--- We really ought to add this stuff where people can see it In the codebase and the samples/tutorials. A banner link to the codebase site would also be helpful... This would prevent redundant user questions (like ours) I glanced over it and will attempt deploying your idea. I noted only a mention of the creation/destruction... Which order of events? And what about detecting a position discrepancy? We both know the entityxyz lies. It seems to report the "desired target position" |
| ||
Here's a sort of sample tester thing, ripped out of my engine. (I actually load an animmesh and index it to a type array, of course) Type CamD Field Body ;Camera parent object Field Camera ;ACTUAL Camera - Man to be... (Head) Field Head ;Error discrepancy detector 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) End Type Global Mde=0 ;0=Fork head snagger, 1=Overhead sticker (get stuck) Global Windowed=1,FirstFlag ;Global B3 ;Global C Graphics3D 800,600,0,1-windowed ;Plane of existence l=CreateLight() 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,1,40 PositionEntity b4,80,1,120 cb=CreateBrush(255,0,0) PaintEntity b1,cb PaintEntity b2,cb Global Cam.CamD = New CamD Cam\Camera=CreateSphere() Cam\Body=CreateSphere() Cam\Head=CreateSphere() ScaleMesh cam\Camera,5,5,5 ScaleMesh cam\Head,8,8,8 ScaleMesh cam\Body,10,22,10 EntityRadius Cam\Body,10,22 EntityRadius Cam\Head,8 EntityRadius Cam\Camera,5 PositionEntity Cam\Camera,-20,22+21,50 PositionEntity Cam\Head,-20,22+21,50 PositionEntity Cam\Body,-20,22,50 EntityType Cam\Body,1 EntityType Cam\Head,1 EntityType Cam\Camera,1 EntityType a,2 EntityType b1,2 EntityType b2,2 EntityType b3,2 EntityType b4,2 c=CreateCamera() PositionEntity c,-120,55,-60 PointEntity c,b1 Collisions 1,2,2,2 ;Type 1 to 2, Elips-Poly, Slide TurnEntity Cam\Body,0,90,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 ;RotateEntity Cam\Camera,0,EntityYaw(Cam\Body),0 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,50.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 UpdateInput CollisionHandling UpdateWorld RenderWorld Flip firstflag=1 Wend End Function UpdateInput() ;Turn mxs=0:mys=0:mdr=0 If KeyDown(201) Or KeyDown(73) Then mxs=-3:If Abs(EntityPitch(Cam\Camera)-3)=90 Then mxs=-6 ;up If KeyDown(209) Or KeyDown(81) Then mxs=3:If Abs(EntityPitch(Cam\Camera)+3)=90 Then mxs=6 ;down ;down If KeyDown(205) Or KeyDown(77) Then mys=-3 ;right If KeyDown(203) Or KeyDown(75) Then mys=3 If KeyDown(82) Then PositionEntity Cam\Body,-20,EntityY(Cam\PIdx,False),50,True End If MoveCamStuff 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 RotateEntity Cam\Camera,EntityPitch(Cam\Camera)+mxs,EntityYaw(Cam\Body),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 ;Move If KeyDown(200)=True Or KeyDown(72)=True Then ;DebugLog Str(Int(EntityX(Cam\Head,True)))+","+Str(Int(EntityY(Cam\Head,True)-35))+","+Str(Int(EntityZ(Cam\Head,True))) mdr=10 ;Forward End If If KeyDown(208)=True Or KeyDown(80)=True Then ;DebugLog Str(Int(EntityX(Cam\Head,True)))+","+Str(Int(EntityY(Cam\Head,True)-35))+","+Str(Int(EntityZ(Cam\Head,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$="" If CountCollisions(Cam\Body)=1 And CountCollisions(Cam\Head)=0 Then ;Are we sitting on the ground? Nothing touching 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 ; S#=0 ; TFormPoint 0,0,0,Cam\PIdx,0 ; OY#=TFormedY() ; PositionEntity Cam\Body,EntityX(Cam\Body,True),EntityY(Cam\PIdx,True),EntityZ(Cam\Body,True),False ; MoveCamStuff ;End If ;End If ;Jumping in progress... TranslateEntity Cam\Body,-Sin(EntityYaw(Cam\Body))*mdr,S#,Cos(EntityYaw(Cam\Body))*mdr MoveCamStuff End Function Function CollisionHandling() c=CountCollisions(Cam\Head) If c=1 Then cam\DY#=90 ;Body is good for telling what we've touched - Hands are actually only for ladders n=CountCollisions(Cam\Body) a$="":For t=1 To n;Order collider names by priority below If t>CountCollisions(Cam\Body) Then Exit ;watch the index value! i=CollisionEntity(Cam\Body,t) ;Relevant because many children have same names If t=1 Then If GetParent(cam\body)<>i Then EntityParent Cam\Body,i,True:cam\PIdx=i Next If c<>0 Then ResetEntity Cam\Head End Function Function MoveCamStuff() ;This looked like a global solution, apparently not... TFormPoint 0,30,0,Cam\Body,0 OX#=TFormedX() OY#=TFormedY() OZ#=TFormedZ() PositionEntity Cam\Camera,OX#,OY#,OZ#,True TFormPoint 0,35,0,Cam\Body,0 OX#=TFormedX() OY#=TFormedY() OZ#=TFormedZ() PositionEntity Cam\Head,OX#,OY#,OZ#,True End Function |
| ||
And what about detecting a position discrepancy? We both know the entityxyz lies. About this, read the documentation and you will see : EntityX(Entity,True) retrieves the global coordinate EntityX(Entity,False) retrieves the local coordinate same thing for EntityY, EntityZ, EntityPitch, EntityYaw, EntityRoll |
| ||
What I meant was it sometimes seems (when a collider is pinned), it reports the position you set the entity to go to rather than its physical position. True or false. |