Answer the question
In order to leave comments, you need to log in
Unity raycast hit 2d how to track void?
I shoot from raycast it hits but I can't track when it shoots into the void it just doesn't work
RaycastHit2D hit = Physics2D.Raycast(Vector2.down, Vector2.up);
if (hit.collider == null)
{
scrollSpeed = Mathf.MoveTowards(-10f, 0, velocity * Time.deltaTime);
}
Answer the question
In order to leave comments, you need to log in
hit - will store the last value anywhere. until it hits something.
physics in the unit has no concept - "collided with emptiness".
so you either null before each check (although I don’t remember if it works) or some one global collider/trigger ala “border of the world” to do)
well, in general, the logic of physics involves a reaction to “something that exists”. collisions, intersections, etc.)
try to write
what scrolls / moves / what it always does there, but stops if the beam crashes into something.
To check if there is something in hit, you can comparehit.transform != null
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question