1

I am trying to make a semicircle with a straight line going from its end point to point at a target. I have tried multiple ways for a day now and can't get it to point exactly at a target position. Here is my progress so far:

enter image description here

I'm trying to get the dark green line to go trough the red point on the yellow line.

Posting the code so far:

vector init = <105.45535, 105.83867, 2239.99976>;
vector init_unit = <-0.54465, 0.83867, 0.00000>;
vector target = <106,104,2241>;

default{

    state_entry(){
        llListen(-215485231, "", NULL_KEY, "");
    }

    listen(integer c, string n, key i, string m){
        list temp = llParseString2List(m, ["|"], []);
        init = (vector)llList2String(temp, 0); //position
        init_unit = (vector)llList2String(temp, 1);
        init_unit = llVecNorm(<init_unit.x, init_unit.y, 0.0>); //line norm vector


        float angle = llAtan2(init_unit.y, init_unit.x); //find angle
        rotation delta = llEuler2Rot(<0.0, -PI_BY_TWO, PI>); //extra rotation
        rotation rot = delta * llEuler2Rot(<0.0, 0.0, angle>); //convert from vector to rotation
        init = init + <0.0, -0.45, 0.0>*rot; //make new offset

        vector p1 = target - init;
        float angle2 = llAtan2(p1.y, p1.x);
        rotation rot2 = llEuler2Rot(<0.0, 0.0, angle>);

        vector p2 = init + (<0.0, 0.45, 0.0>*(delta*rot2)); //find last other side of semi circle
        p2 = (p2 + p1) - init;
        float angle3 = llAcos((p1*p2)/(llVecMag(p1)*llVecMag(p2))); //find angle between vectors

        llSetRot(delta * llEuler2Rot(<0.0, 0.0, angle2+angle3>)); //set rotation
        llSetPos(init); //set postion
    }

}

The semicircle is 1m on y axis and middle on each end is +/- <0,0.45,0>. Please ask if anything is unclear.

Helder
  • 468
  • 1
  • 4
  • 15
TeaWave
  • 105
  • 1
  • 2
  • 7

0 Answers0