|
@@ -51,8 +51,7 @@ Function QCollide:QResult( collider:ConvexCollider,src:Vec3f,dst:Vec3f,moving:Bo
|
|
|
|
|
|
' debug+=", "
|
|
' debug+=", "
|
|
|
|
|
|
- If cresult.normal.y>.7071
|
|
|
|
-' Print "hitground "+cresult.normal
|
|
|
|
|
|
+ If cresult.normal.y>.7'9
|
|
qresult.hitground=True
|
|
qresult.hitground=True
|
|
Endif
|
|
Endif
|
|
|
|
|
|
@@ -62,46 +61,53 @@ Function QCollide:QResult( collider:ConvexCollider,src:Vec3f,dst:Vec3f,moving:Bo
|
|
|
|
|
|
Local plane:=New Planef( cresult.point,cresult.normal )
|
|
Local plane:=New Planef( cresult.point,cresult.normal )
|
|
plane.d-=margin
|
|
plane.d-=margin
|
|
-
|
|
|
|
|
|
+
|
|
Local d0:=plane.Distance( src ),d1:=plane.Distance( dst )
|
|
Local d0:=plane.Distance( src ),d1:=plane.Distance( dst )
|
|
|
|
|
|
Local tline:=New Linef( src,dst-src )
|
|
Local tline:=New Linef( src,dst-src )
|
|
|
|
|
|
Local t:=plane.TIntersect( tline )
|
|
Local t:=plane.TIntersect( tline )
|
|
|
|
|
|
- If t>0 src=tline * t
|
|
|
|
|
|
+ If t>0
|
|
|
|
+ src=tline * t
|
|
|
|
+ Endif
|
|
|
|
|
|
If Not moving Or t>=1
|
|
If Not moving Or t>=1
|
|
dst=src
|
|
dst=src
|
|
Exit
|
|
Exit
|
|
Endif
|
|
Endif
|
|
-
|
|
|
|
|
|
+
|
|
Select state
|
|
Select state
|
|
Case 0
|
|
Case 0
|
|
- dst=plane.Nearest( dst )
|
|
|
|
-' debug+="A "+P( plane )
|
|
|
|
|
|
+
|
|
|
|
+ Local tdst:=plane.Nearest( dst )
|
|
|
|
+
|
|
|
|
+ If plane.n.y<.1 And tdst.y>src.y
|
|
|
|
+ dst=src
|
|
|
|
+ Exit
|
|
|
|
+ Local t:=(tdst.y-src.y)/(tdst-src).Length
|
|
|
|
+ tdst=(tdst-src)*t+src
|
|
|
|
+ Print "Here!"
|
|
|
|
+ Endif
|
|
|
|
+
|
|
|
|
+ dst=tdst
|
|
|
|
+
|
|
plane0=plane
|
|
plane0=plane
|
|
state=1
|
|
state=1
|
|
Case 1
|
|
Case 1
|
|
Local v:=plane0.n.Cross( plane.n )
|
|
Local v:=plane0.n.Cross( plane.n )
|
|
- If v.Length>.001
|
|
|
|
|
|
+
|
|
|
|
+ If v.Length>.00001
|
|
Local groove:=New Linef( src,v )
|
|
Local groove:=New Linef( src,v )
|
|
-' Local d0:=plane0.Distance( dst )
|
|
|
|
dst=groove.Nearest( dst )
|
|
dst=groove.Nearest( dst )
|
|
-' debug+="B "+P( plane )+" d0="+F(d0)+" sd0="+F(plane0.Distance(src))+" dd0="+F(plane0.Distance(dst))
|
|
|
|
plane1=plane
|
|
plane1=plane
|
|
state=2
|
|
state=2
|
|
Else
|
|
Else
|
|
Print "QCollide OOPS2"
|
|
Print "QCollide OOPS2"
|
|
-' debug+="C "+P( plane )
|
|
|
|
- dst=plane.Nearest( dst )
|
|
|
|
- plane0=plane
|
|
|
|
- state=1
|
|
|
|
|
|
+ dst=src
|
|
|
|
+ Exit
|
|
Endif
|
|
Endif
|
|
Case 2
|
|
Case 2
|
|
-' Local d0:=plane0.Distance( dst )
|
|
|
|
-' Local d1:=plane1.Distance( dst )
|
|
|
|
-' debug+="D "+P( plane )+" d0="+F(d0)+" d1="+F(d1)
|
|
|
|
dst=src
|
|
dst=src
|
|
Exit
|
|
Exit
|
|
End
|
|
End
|
|
@@ -128,6 +134,11 @@ Class CharacterController Extends Behaviour
|
|
Return _onground
|
|
Return _onground
|
|
End
|
|
End
|
|
|
|
|
|
|
|
+ Property OnWall:Bool()
|
|
|
|
+
|
|
|
|
+ Return _onwall
|
|
|
|
+ End
|
|
|
|
+
|
|
Property StepDown:Float()
|
|
Property StepDown:Float()
|
|
|
|
|
|
Return _stepDown
|
|
Return _stepDown
|
|
@@ -145,6 +156,8 @@ Class CharacterController Extends Behaviour
|
|
|
|
|
|
Field _onground:Bool
|
|
Field _onground:Bool
|
|
|
|
|
|
|
|
+ Field _onwall:Bool
|
|
|
|
+
|
|
Field _vel:Vec3f
|
|
Field _vel:Vec3f
|
|
|
|
|
|
Method OnUpdate( elapsed:Float ) Override
|
|
Method OnUpdate( elapsed:Float ) Override
|
|
@@ -180,21 +193,25 @@ Class CharacterController Extends Behaviour
|
|
|
|
|
|
Local dst:=Entity.Position
|
|
Local dst:=Entity.Position
|
|
|
|
|
|
- Local qres:=QCollide( Cast<ConvexCollider>( Entity.Collider ),src,dst,moving Or Not _onground )
|
|
|
|
|
|
+ Local qres:=QCollide( Cast<ConvexCollider>( Entity.Collider ),src,dst,True )'moving Or Not _onground )
|
|
dst=qres.position
|
|
dst=qres.position
|
|
-
|
|
|
|
|
|
+#rem
|
|
If Not _jumping And Not qres.hitground And _onground
|
|
If Not _jumping And Not qres.hitground And _onground
|
|
src=dst
|
|
src=dst
|
|
dst.y-=_stepDown
|
|
dst.y-=_stepDown
|
|
qres=QCollide( Cast<ConvexCollider>( Entity.Collider ),src,dst,False )
|
|
qres=QCollide( Cast<ConvexCollider>( Entity.Collider ),src,dst,False )
|
|
dst=qres.position
|
|
dst=qres.position
|
|
Endif
|
|
Endif
|
|
-
|
|
|
|
|
|
+#end
|
|
_onground=qres.hitground
|
|
_onground=qres.hitground
|
|
-
|
|
|
|
- If _onground _jumping=False
|
|
|
|
|
|
+ _onwall=qres.hitwall
|
|
|
|
|
|
- _vel.y=dst.y-src.y
|
|
|
|
|
|
+ If _onground
|
|
|
|
+ _jumping=False
|
|
|
|
+ _vel.y=0
|
|
|
|
+ Else
|
|
|
|
+ _vel.y=dst.y-src.y
|
|
|
|
+ Endif
|
|
|
|
|
|
Entity.Position=dst
|
|
Entity.Position=dst
|
|
End
|
|
End
|
|
@@ -318,7 +335,7 @@ Class MyWindow Extends Window
|
|
Local controller:=_player.GetComponent<CharacterController>()
|
|
Local controller:=_player.GetComponent<CharacterController>()
|
|
|
|
|
|
' canvas.DrawText( "y="+_player.Position.y+" onground="+controller.OnGround+" FPS="+App.FPS,0,0 )
|
|
' canvas.DrawText( "y="+_player.Position.y+" onground="+controller.OnGround+" FPS="+App.FPS,0,0 )
|
|
- canvas.DrawText( " onground="+controller.OnGround+" FPS="+App.FPS,0,0 )
|
|
|
|
|
|
+ canvas.DrawText( " onground="+controller.OnGround+" onwall="+controller.OnWall+" FPS="+App.FPS,0,0 )
|
|
End
|
|
End
|
|
|
|
|
|
End
|
|
End
|