Jump to content

Rotate on Movement Script


HSHPrincessofCarlisne
 Share

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

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

Recommended Posts

Hello, everyone; 

So, I have a wearable/attachable car I've been working on, but the wheels are static; they don't turn. I have another car from a creator on the marketplace which is also wearable and the wheels turn when you move; 

I was wondering if anybody knew of any rotation scripts I can put in wheel prims that trigger when movement is detected.

I don't have any scripting experience besides putting scripts along with other items inside objects and using the ACS vehicle operating system to make rezzable, drivable vehicles. 

- Charlotte Sinclair 

Link to comment
Share on other sites

  • 1 month later...
// Quick script example of how to rotate some wheels on an attached vehicle.
// Usage: name your linked wheel object(s) 'wheel'. Drop the script in. Attach and then use left and right turning keys. 
// For a quick demo, create 3 prims, resize two of them to be thinner/more wheel like and name them 'wheel'. Space them out. Link those two to the third prim. Drop this script into it and then attach the whole thing on avatar center.

list wheelLinks; // List of links for wheels because I assume you're wheels are separate link objects.

rotation defaultRot; // Default wheel rotation. // Whatever they start at.

float wheelTurnAmount = 40; // Degrees to turn the wheels.

default
{
    state_entry()
    {        
        integer i = 0;
        integer len = llGetNumberOfPrims();
        
        for( i; i <= len; i++ ) { // When the script is first dropped into the attachment, we loop through all prims looking for any with the name 'wheel' and save their link numbers.
            string linkName = llGetLinkName(i);
            
            if( llToLower(linkName) == "wheel" ) {
                wheelLinks += i;
                defaultRot = (rotation)llList2String(llGetLinkPrimitiveParams(i, [PRIM_ROTATION]), 0);
            }            
        }
    }

    control(key id, integer level, integer edge)
    {
        integer start = level & edge;
        integer end = ~level & edge;
        integer held = level & ~edge;
        integer untouched = ~(level | edge);        
    
        
        if( start & CONTROL_ROT_RIGHT ) { // Turn wheels right
            integer i = 0;
            integer len = llGetListLength(wheelLinks);
            
            for( i; i <= len; i++ ) {
                integer wheelLink = (integer)llList2String(wheelLinks, i); // Link number of a wheel
                vector wheelAngle = <0,0,-wheelTurnAmount>; // Vector for turning the wheel
                wheelAngle = wheelAngle * DEG_TO_RAD; // Turn euler angles into radians.
                llSetLinkPrimitiveParamsFast( wheelLink, [PRIM_ROTATION, llEuler2Rot(wheelAngle)] ); 
            }            
        }
        else if( start & CONTROL_ROT_LEFT ) { // Turn wheels left.
            integer i = 0;
            integer len = llGetListLength(wheelLinks);
            
            for( i; i <= len; i++ ) {
                integer wheelLink = (integer)llList2String(wheelLinks, i); // Link number of a wheel
                vector wheelAngle = <0,0,wheelTurnAmount>; // Vector for turning the wheel
                wheelAngle = wheelAngle * DEG_TO_RAD; // Turn euler angles into radians.
                llSetLinkPrimitiveParamsFast( wheelLink, [PRIM_ROTATION, llEuler2Rot(wheelAngle)] ); 
            }                  
        }        
        else if( end & CONTROL_ROT_LEFT ) { // Reset wheels
            integer i = 0;
            integer len = llGetListLength(wheelLinks);
            
            for( i; i <= len; i++ ) {
                integer wheelLink = (integer)llList2String(wheelLinks, i); // Link number of a wheel
                llSetLinkPrimitiveParamsFast( wheelLink, [PRIM_ROTATION, defaultRot] ); 
            }                
        }                
        else if( end & CONTROL_ROT_RIGHT ) { // Reset wheels.
            integer i = 0;
            integer len = llGetListLength(wheelLinks);
            
            for( i; i <= len; i++ ) {
                integer wheelLink = (integer)llList2String(wheelLinks, i); // Link number of a wheel
                llSetLinkPrimitiveParamsFast( wheelLink, [PRIM_ROTATION, defaultRot] ); 
            }              
        }
           
    }  
    
    attach( key id ) { if( id ) { llRequestPermissions(id, PERMISSION_TAKE_CONTROLS);  } } // On attach, request permission to 'take controls'
    
    run_time_permissions(integer perm) { // When take controls permission is granted, we take control of the avatars left and right turning.
        if(PERMISSION_TAKE_CONTROLS & perm) { llTakeControls( CONTROL_ROT_LEFT | CONTROL_ROT_RIGHT, TRUE, TRUE); } // Set last value to FALSE if you don't want normal avatar rotation. I assume you have other vehicle scripts that will handle this.
    } 
}

 

Edited by Raven Huntsman
  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 582 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...