D
D
DALVROT2021-08-25 16:18:41
Unity
DALVROT, 2021-08-25 16:18:41

Physics2D.Raycast not working, why?

In general, the code that worked properly stopped working, I can’t figure out what’s wrong. hit2Dir always has a value, hit2.point = (0,0), and with hit2.collider.name an error occurs (because the raycast does not hit anywhere, although there is an object above it), when hit3 always works. What could be the problem?

Code
hit2 = Physics2D.Raycast(posOfHit, hit2Dir, maskGround);
            print("hit2.point: " + hit2.point /*+ "hit2.collider: " + hit2.collider.name*/);
            hit3 = Physics2D.Raycast(posOfHit, hit2Dir * -1, maskGround);
            print("hit3.point: " + hit3.point + "hit3.collider: " + hit3.collider.name);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question