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. Dismiss Notice

Question How do I script so that objects would be placed at the ends of rays using Ray Perception Sensor 3D

Discussion in 'Scripting' started by unity_16BEB1D569830D462973, Jul 6, 2023.

  1. unity_16BEB1D569830D462973

    unity_16BEB1D569830D462973

    Joined:
    Mar 15, 2023
    Posts:
    5
    I am trying to generate a script where objects will be placed at the ends of the rays from the Ray Perception Sensor 3D automatically. I did develop a script for it but it did not work and was wondering if the forum has a suggested script for it.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Rays in Unity don't have an end. They are an origin and a direction.

    There is a method to get the point on a Ray at any given distance from the origin.

    If the Rays you are talking about are something else, perhaps post the documentation reference for it?
     
  3. unity_16BEB1D569830D462973

    unity_16BEB1D569830D462973

    Joined:
    Mar 15, 2023
    Posts:
    5
    Thank you for your reply. So the scenario was an agent would be detect a wall, and on that wall it would place an object. How would I get the point hitting on the wall?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    That's given back to you via the RaycastHit structure.

    Check out any of the Physics "cast" commands, such as Physics.Raycast (or Physics2D.Raycast)