Question by
Tarokh · Jun 29, 2017 at 10:52 PM ·
raycastcollidercollider2d
Physic2D and Raycast2D on 3D Colliders problem...
I'm making a 2D game and I was fixing the 'Infinite Jump' problem (which allows you to jump infinite time in mid-air) I managed to fix the problem using Raycast but I used 3D raycast and I had to use a 3D collider (I think it's because 2D colliders don't have Z axis, so it doesn't work on them.), considering that is there a way to use 2D raycast and 2D colliders? I'm new to scripting so explanation would be appreciated, thanks :D here's the code I used:
RaycastHit hit;
void Update ()
{
if (Physics.Raycast (transform.position, Vector2.down,out hit, RayDist)) {
if (hit.collider) {
grounded = true;
}
}
if (!Physics.Raycast (transform.position, Vector2.down,out hit, RayDist)) {
grounded = false;
}
if (grounded == true) {
if (Input.GetKeyDown (KeyCode.Space)) {
Jump ();
}
}
Comment