Thanks ilan for the code, it is very easy to detect collisions this way!
In summary, my application requires several characters that do not collide with each other, but that do collide with other elements, and following the indications of EREL in this thread
https://www.b4x.com/android/forum/threads/xui2d-to -collide-or-not-to-collide.97144 / # post-760005, I have managed not to collide! (Thanks Erel for this.)
However, after making several code attempts to make my character (man) hit the wall and change direction (I defined my character as an arrangement in Game and defined a class for my character), I am presenting 2 problems.
1) When I create a single character "mMan (1)" when it hits the wall, it presents a strange behavior. Initially I thought that my logic was wrong (and it was very strenuous since I create like 3 different routines thinking that I could not find the logic), but when I created several "mMan (5)" characters, I realized that the algorithm does work some of they however strange behavior continues to present itself.
2) When creating several characters I see that they do not move independently, instead there are characters (man) that without having hit the wall are returned when others do collide.
this is the code in the man class for change direction of man
Public Sub Tick
If speed_man>0 Then
direction_man="right"
Else
If speed_man<0 Then
direction_man="left"
Else
If speed_man=0 Then
direction_man="still"
End If
End If
End If
If direction_man="right" Then
bw.Body.LinearVelocity.X=speed_man
bw.FlipHorizontal=False
Else
If direction_man="left" Then
bw.Body.LinearVelocity.X=speed_man
bw.FlipHorizontal=True
If direction_man="still" Then
bw.Body.LinearVelocity.X=speed_man 'if still so nothing happens
End If
End If
End If
If collide_with_wall=True Then
If direction_man="right" Then
speed_man=-1
Else
If direction_man="left" Then
speed_man=1
End If
End If
End If
End Sub
this is the code in Game
Sub Class_Globals
Dim quantity_mans As Int =5
Public mMan(quantity_mans) As Man
.
.
.
End sub
Private Sub World_BeginContact (Contact As B2Contact)
Dim bodies As X2BodiesFromContact = X2.GetBodiesFromContact(Contact, "characterman")
If bodies = Null Then Return
If bodies.OtherBody.Name = "pared" Then
button2.Text="touch wall"'this line just is an indicator
For identifier_mans=0 To quantity_mans - 1
mMan(identifier_mans).collide_with_wall=True
Next
End If
End Sub
Private Sub World_EndContact(Contact As B2Contact)
Dim bodies As X2BodiesFromContact = X2.GetBodiesFromContact(Contact, "characterman")
If bodies <> Null Then
button2.Text="no touch"'this line just is an indicator
For identifier_mans=0 To quantity_mans - 1
mMan(identifier_mans).collide_with_wall=False
Next
End If
End Sub
And this is the behavior with 1 and severals characters. (some men stick to the wall)
View attachment 99164