Jump to content

lost once more in the world of rotations


Tealthantos
 Share

You are about to reply to a thread that has been inactive for 4234 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Since my first attempt at creating a turret (http://community.secondlife.com/t5/LSL-Scripting/Lost-in-the-world-of-rotations/td-p/1666849) I've come across another turret script that I've been attempting to modify for my tank, however I've been having problems getting it to follow both the Z and Y axis at the same time, when I turn the turret and increase the elevation - it will return to zero rotation then will elevate up along the y axis before returning to zero rotation then back to its location along the Z axis.

 

Here is the script -

 

rotation old_rot;
key pilot;
vector calculate_rot;
float scan_delay = .01;
float max_roty=8;
float max_rotz=8;

rotateToz(float angle)
{
   
    rotation new_rotz = llEuler2Rot(<0,0,angle>);
    float aim_change=llFabs(llAngleBetween(old_rot,new_rotz));
    if(aim_change > max_rotz)
    {
    calculate_rot = llRot2Euler(llEuler2Rot(<0,0,angle>)/old_rot);
    if(calculate_rot.z > max_rotz) calculate_rot.z=max_rotz;
    else calculate_rot.z=-max_rotz;
    old_rot = llEuler2Rot(calculate_rot)*old_rot;
    }
    else{
    old_rot = new_rotz;}
    llSetLocalRot(new_rotz);
}

rotateToy(float angle)
{
    rotation new_roty = llEuler2Rot(<0,angle,0>);
    float aim_change=llFabs(llAngleBetween(old_rot,new_roty));
    if(aim_change > max_roty)
    {
    calculate_rot = llRot2Euler(llEuler2Rot(<0,angle,0>)/old_rot);
    if(calculate_rot.y > max_roty) calculate_rot.y=max_roty;
    else calculate_rot.y=-max_roty;
    old_rot = llEuler2Rot(calculate_rot)*old_rot;
    
    }
    else{
    old_rot = new_roty;
    }
    llSetLocalRot(new_roty);
}


default
{
    
    on_rez(integer t)
    {
        llResetScript();
    }
    
    link_message(integer sender, integer channel, string message, key id)
    {
        if(message=="seated")
        {
            pilot = id;
            if(channel)
            {
                llSetTimerEvent(scan_delay);
            }else
            {
                llSetTimerEvent(0);
                
            }
        }
    }
    
    timer()
    {
        llSetTimerEvent(0);
        integer info = llGetAgentInfo(pilot);
        if((info & AGENT_MOUSELOOK) && (info & AGENT_SITTING))
        {
            llSensor("", pilot, AGENT, 10.0, TWO_PI);
        }else
        {
            llSetTimerEvent(scan_delay);
        }
    }
    
    sensor(integer num_detected)
    {
        llSetTimerEvent(0);
        {
            vector compensated = llRot2Euler(llGetRootRotation() / llDetectedRot(0));
            rotateToy(compensated.y * -1);
            rotateToz(compensated.z * -1);
            llSetTimerEvent(scan_delay);
        }
    }
    
}

 

Now I suspect this part here is the problem

 

   {
            vector compensated = llRot2Euler(llGetRootRotation() / llDetectedRot(0));
            rotateToy(compensated.y * -1);
            rotateToz(compensated.z * -1);
            llSetTimerEvent(scan_delay);
        }

 

But however I am a bit unsure as my abilities with second life script leaves a -lot- to be desired.

 

Any help would be appreciated.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4234 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...