hey there,
i’m playing around with raytrace in defualt 2d workspace, and for the most part everything i do with raycast works perfectly
BUT !
there is a certain case where things get weird
it only works one way, like this screenshot shows, the raycast ‘collides’ with block tile normally…
but if the origin and target are reversed, for some reason raycast won’t detect the blocking tile
and I’m loosing my mind and precious sleep … any ideas what I’ve missed ?
Vector2 currentLoc2d = new Vector2(currentCharacter.transform.localPosition.x, currentCharacter.transform.localPosition.y);
Vector2 targetLoc2d = new Vector2(currentCharacter.ai_target.x, currentCharacter.ai_target.y);
float distanceToTrace = Vector2.Distance(currentLoc2d, targetLoc2d);
RaycastHit2D hit = Physics2D.Raycast(currentLoc2d, targetLoc2d, distanceToTrace, 1 << 9);
if (hit != null)
{
if (hit.transform != null )
{
Debug.LogWarning(hit.transform.tag);
}