Games [XUI2D] World RayCast - Callback Procedure

Gunther

Active Member
Licensed User
Longtime User
hi,

what is the correct definition for the CallBack-Procedure for the call of:

B4X:
world.RayCast(p1 , p2)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code is from the walking character example:
B4X:
Private Sub Panel1_Touch (Action As Int, X As Float, Y As Float)
   If Action = Panel1.TOUCH_ACTION_DOWN Then
       Dim p As B2Vec2 = X2.ScreenPointToWorld(X, Y)
       'cast a ray from the kid to the point
       RaycastBody = Null
       RaycastPoint = p
       world.RayCast(mKid.bw.Body.Position, p)
       If RaycastBody <> Null And RaycastBody.IsDeleted = False Then
           'ray hit a body
           RaycastBody.TimeToLiveMs = 1
       End If
       CreateLaser
   End If
End Sub

Private Sub World_RaycastCallback (Fixture As B2Fixture, Point As B2Vec2, Normal As B2Vec2, Fraction As Float) As Float
   Dim bw As X2BodyWrapper = Fixture.Body.Tag
   'ignore static bodies
   If bw.Body.BodyType = bw.Body.TYPE_STATIC Then Return -1
   RaycastBody = bw
   RaycastPoint = Point.CreateCopy
   'return fraction to limit the ray up to the current fixture.
   'The result is that the last event will be the closest body.
   Return Fraction
End Sub

SS-2018-11-01_08.24.15.png
 
Last edited:

Gunther

Active Member
Licensed User
Longtime User
Thanks, it was not searchable/findable in the forum since packed inside the examples.

Too much news things to remember, what is where and how. :)
 
Top