Search Unity

midpoint between two objects

Discussion in 'Scripting' started by qualtext, Jan 8, 2010.

  1. qualtext

    qualtext

    Joined:
    Jan 8, 2010
    Posts:
    10
    hi community.

    can somebody help me? i am searching a function which calculate the midpoint-vector-coordinate between two objects.

    there are two players and one camera. the target of the camera should be on this position (red point in attachment).

    thank you very much.
     

    Attached Files:

  2. vogles

    vogles

    Joined:
    Sep 28, 2009
    Posts:
    131
    basic vector math.

    (destination - origin) * 0.5f;

    So in your case: ((Box.transform.position - Capsule.transform.position) * 0.5f) + Capsule.transform.position;
     
  3. mdrunk

    mdrunk

    Joined:
    Apr 26, 2014
    Posts:
    11
    why not just lerp it at 0.5f?
     
    pginiotis likes this.