Search Unity

Angle Question

Discussion in 'Scripting' started by sacmanis, Sep 24, 2017.

  1. sacmanis

    sacmanis

    Joined:
    Feb 25, 2016
    Posts:
    9
    To set the scene as shown in the picture.

    Marker 1 is placed anywhere with no restrictions. It's rotation is always 0,0,0.

    Marker 2 can then be placed anywhere with no restrictions. It's rotation is set to Lookat Marker 1. The line is created showing the area within the markers. It is set to loop hence the return to marker 1.

    A check is made to see if Angle Lock is set. If it is, subsequent markers must be placed at 90 degree increments. so that everything 'snaps' to a grid. This is where I am failing. The angles are simply eluding me on this one.

    Marker 3 is the active marker and is attached to an empty in front of the player using a raycast to keep it close to the terrain. Currently this is set to Lookat the previous marker. In this case marker 2.

    I have tried multiple angle solutions and I am missing something. I need the angle created by all three markers to be 90 degrees or 180, or -90/270. I assumed that since the 2nd marker is looking at the 1st, then transform.angle would give me the angle I need but that is not the case.every solution I have tried will get 90 degree snaps of every marker after the second one but it will not include the 1st one. But they are all relative to World Space not local space.

    All of the placed markers are parented to an empty to keep them together. So it appears that I am after the local rotations not the global but I am getting the global.

    What am I missing?

    upload_2017-9-23_23-14-53.png upload_2017-9-23_23-14-53.png
     
  2. sacmanis

    sacmanis

    Joined:
    Feb 25, 2016
    Posts:
    9
  3. sacmanis

    sacmanis

    Joined:
    Feb 25, 2016
    Posts:
    9
    For what it's worth, I figured it out. Once I drew out what I was actually getting from the various angle options, I became obvious where my mistake was.
     
    AcidArrow likes this.