Search Unity

How to "freeze" raycasts in time to create physical 3d lines around the game world?

Discussion in 'Scripting' started by StaplesJay, Jul 28, 2017.

  1. StaplesJay

    StaplesJay

    Joined:
    Jun 8, 2017
    Posts:
    1
    Hey there, I'm looking to create an fps shooter where all the raycasts shot from guns last an infinitely long time rather than for one single frame. For example if the player or enemy was to walk into a raycast 60 frames after it was cast it should still effect the game object as intended if it was hit directly on that frame. Is this possible in Unity and if so where do I get started in doing this?

    I've had the idea to turn the raycast line itself into a physical collider or a game object but I have no idea how to do this.

    Also been thinking about the possibility of tracking the players and enemies movement is a way similar to the old 2d Snake game where the "trails" of where they've been last forever, and work as a simple wall, is this too also possible?

    Big thanks :)
     
    Last edited: Jul 28, 2017
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Simplest way would simply be to save the rays into a collection. Then each frame iterate over all of the rays and perform a new raycast.

    You could also replace the ray with a long thin box collider. But my gut tells me raycasts will outperform box colliders for this application.
     
    StaplesJay likes this.