Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Raycast with wrapped screen

Discussion in '2D' started by Pyrre, May 5, 2020.

  1. Pyrre

    Pyrre

    Joined:
    May 5, 2020
    Posts:
    1
    Hello,
    In my game my screen is wrapped, so every object that crosses right border appears on the left and if it crosses top border it appears on the bottom. I want raycast of limited range from player position also follow that rule. Any help is appreciated!
     
  2. nabrown

    nabrown

    Joined:
    Jun 27, 2019
    Posts:
    27
    Seems like you would need to have a method that you use instead of directly calling raycasts. That method would look at the raycast origin, direction, and distance and determine if the resulting ray will cross the left or right boundry. If so, it creates a second ray on the opposite boundary with the same direction and distance equal to the remaining distance. It would then combine all the hits and return them as a single list.

    Haven't tested this but it seems like it would work.