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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Determine point between Main Camera and Game Object

Discussion in 'Scripting' started by eco_bach, Mar 31, 2017.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    For a particle effect I need to determine the precise point (Vector 3) a specific distance from my Main Camera and directly between my Main Camera and a specific Game Object or target.

    Would I use the Physics.Linecast method or?
     
  2. dterbeest

    dterbeest

    Joined:
    Mar 23, 2012
    Posts:
    389
    using some vector math:
    Code (csharp):
    1. Vector3 camPos;
    2. Vector3 objectPos;
    3.  
    4. Vector3 direction = (objectPos - camPos).normalized;
    5. Vector3 resultPos = direction * distance;
     
    KelsoMRK and Dave-Carlile like this.
  3. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Thanks! Will try that.