With this test code (which is wrong):
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector3 p1 = Camera.main.ScreenToWorldPoint(LastMousePos);
Vector3 p2 = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D h = Physics2D.Raycast(p1, p2);
Debug.Log(p1 + " -> " + p2 + " = " + h.collider);
LastMousePos = Input.mousePosition;
}
}
What should I be using for p2? I wish Raycast() had a version that took source + destination, but instead it wants direction (and optionally distance). So starting with source + destination, how do I get direction and distance?
I want the above code to find any collider between the last 2 mouse clicks. It works (in limited test cases I’ve tried) going in one direction, but not the other.
This is a 2D game. I want to detect any objects hit as the user drags the mouse across the screen. I know how to check for a hit at the current mouse location, but I also want to catch times when they drag over an object really fast (before the next Update/frame). I guess I’ll probably change to RaycastAll in my final code, but shouldn’t matter for sake of this question.