rendom
rendom

Reputation: 3715

Raycast end position is wrong for some strange reason

As you can see from this simple code I'm casting 3 rays and red ray should be similar to magenta line it must go from startPos to endPos. But for some reason red ray is copying yellow line.

Can't understand what is wrong...

Vector2 startPos = transform.position;
Vector2 endPos = transform.position + transform.up * 3f;

Debug.DrawRay(Vector3.zero, startPos, Color.green);
Debug.DrawRay(Vector3.zero, endPos, Color.yellow);

Debug.DrawLine(startPos, endPos, Color.magenta);

Debug.DrawRay(startPos, endPos, Color.red);

enter image description here

Upvotes: 1

Views: 128

Answers (1)

frogatto
frogatto

Reputation: 29285

According to the doc, Debug.DrawRay(start, dir) draws a line from start to start + dir.

Draws a line from start to start + dir in world coordinates.

So, Debug.DrawRay(startPos, endPos, Color.red); draws a line from startPos to startPos + endPos.

Upvotes: 1

Related Questions