I'm experimenting with 2d physics, and the problem is this: The IsTouchingLayers
function reveals that the object is touching a layer, but only if I use the-1
parameter which is equivalent to Physics2D.AllLayers
.
These are the tests done on Visual Studio in debug in the immediate control window:
?Physics2D.AllLayers
-1
?GroundCheck.IsTouchingLayers(-1)
true
?GroundCheck.IsTouchingLayers(0)
false
?GroundCheck.IsTouchingLayers(1)
false
?GroundCheck.IsTouchingLayers(2)
false
?GroundCheck.IsTouchingLayers(3)
false
?GroundCheck.IsTouchingLayers(4)
false
?GroundCheck.IsTouchingLayers(5)
false
?GroundCheck.IsTouchingLayers(6)
false
?GroundCheck.IsTouchingLayers(7)
false
?GroundCheck.IsTouchingLayers(8)
false
?GroundCheck.IsTouchingLayers(9)
false
?GroundCheck.IsTouchingLayers(10)
false
?GroundCheck.IsTouchingLayers(11)
false
?GroundCheck.IsTouchingLayers(12)
false
?GroundCheck.IsTouchingLayers(13)
false
?GroundCheck.IsTouchingLayers(14)
false
?GroundCheck.IsTouchingLayers(15)
false
?GroundCheck.IsTouchingLayers(16)
false
?GroundCheck.IsTouchingLayers(17)
false
These are the layers I have in the project:
If I use the -1
parameter it works correctly, the character jumps when it touches the ground and does not jump when it is in the air, but it will definitely jump by touching any layers. And anyway I want to understand why.
What am I doing wrong ?
Thank you