Search Unity

Problem with transform.position when target are very close

Discussion in 'Scripting' started by seronni, Jul 5, 2015.

  1. seronni

    seronni

    Joined:
    Jun 25, 2015
    Posts:
    18
    Hi,

    In the follow code:
    Code (CSharp):
    1. Vector3 relativePosition = myTarget.transform.position - transform.position;
    2.  
    When I debug and my target are very close, I don't Know why but Unity sets the Y point negative like -0,87 and sometimes positive like 0,95. So when this happens changes everything because delta variable will grow. Can anyone help me?
     
    Last edited: Jul 6, 2015
  2. seronni

    seronni

    Joined:
    Jun 25, 2015
    Posts:
    18
    Forgot to say that the test I did was with a static target, ie, it would be unable to change his position.
     
  3. seronni

    seronni

    Joined:
    Jun 25, 2015
    Posts:
    18
    Anyone, plz help me! Why Unity when get position of statics gameobjects, have a little diference every time?
     
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    that's a lot of math... what are you trying to achieve with it?
     
  5. seronni

    seronni

    Joined:
    Jun 25, 2015
    Posts:
    18
    LeftyRighty,

    The objective of the code is to find the two angles to hit a target. In fact it already does perfectly. However, when the target is very close he gets crazy because as point Y time is negative time gives positive he is changing the angles.
     
  6. seronni

    seronni

    Joined:
    Jun 25, 2015
    Posts:
    18
    I delete the code, because I spend alot time to do that, and I will sell it. So the thing is, I get the relative position of an static object, but for some reason the Yp of the relative position time is negative and time is positive at each frame