Games [XUI2D] World RayCast - Callback Procedure

Discussion in 'Game Development' started by Gunther, Oct 31, 2018.

  1. Gunther

    Gunther Active Member Licensed User

    hi,

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

    Code:
    world.RayCast(p1 , p2)
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    This code is from the walking character example:
    Code:
    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
    [​IMG]
     
    Last edited: Nov 4, 2018
    Gunther likes this.
  3. Gunther

    Gunther Active Member Licensed 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. :)
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Please ask as many questions as you have (each one in its own thread like you did here). This will help other developers to find answers in the future.
     
    ilan and Gunther like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice