Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. We are looking for your feedback about Templates! Tell us about your experiences by taking our survey.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

What is Raycast?

Discussion in 'Unity Certification' started by vidit0210, Apr 27, 2016.

  1. vidit0210

    vidit0210

    Joined:
    Dec 30, 2015
    Posts:
    30
    Can Someone please explain me what is a ray cast and how it is used in Games?
    Sorry to be a noob but I don't understand it
     
  2. CrymX

    CrymX

    Joined:
    Feb 16, 2015
    Posts:
    179
    In a shooter game like counter strike, when you shoot, the bullet is no a gameObject travelling fast, but is a "Ray" from the gun to N distance. And every player in this ray get damaged.

    Is my example clear ?
     
    zbagusgaps, Aroyj and vidit0210 like this.
  3. DanVioletSagmiller

    DanVioletSagmiller

    Joined:
    Aug 26, 2010
    Posts:
    150
    https://unity3d.com/learn/tutorials/modules/beginner/physics/raycasting
    - Ray is where something starts at a point, and then creates a line (you cannot see) in some direction away. The idea is that it then follows this line to see if it collides with anything.


    In Physics, the collision is used to detect that something is that direction, or finding out whats in front. I.e. if you have a space ship flying forward, and a raycast from the ship forward collides with an asteroid. Now your AI makes the ship go turn or stop.


    In Rendering, a RayCast is an operation from the camera point sending out a "ray" find the surface it collides with and then render the material on that surface for that pixel in the screen. Additionally, light sources may cast rays, and see if that shows a reflection on that material.


    There is a lot that rays can do. I strongly suggest following the tutorial to learn more about it.
    https://unity3d.com/learn/tutorials/modules/beginner/physics/raycasting
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,882
    Read the docs first: http://docs.unity3d.com/ScriptReference/Physics.Raycast.html
    It's simply a way to shoot a line and see if it hits a collider. If it hits a collider you can get useful information about it. It's used for gathering information in 3D space using the physics engine.

    You can use it to answer questions similar to:

    "Is there an object behind me?"

    "What is the 3D position of what my line touches?"

    "What angle is the surface where my ray touches?"

    And so on... lots of information. That's the purpose of using them.
     
unityunity