Advertisement
Teonnyn

Untitled

Mar 7th, 2023
1,597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Define the leg object names
  2. string leg_top = "leg_top";
  3. string leg_mid = "leg_mid";
  4. string leg_bot = "leg_bot";
  5.  
  6. // Define the vehicle object name
  7. string vehicle = "vehicle";
  8.  
  9. // Define the position and rotation offsets for each leg object
  10. vector top_offset = <0.0, 0.0, 0.1>;
  11. rotation top_rotation = <0.0, 0.0, 0.0, 1.0>;
  12. vector mid_offset = <0.0, 0.0, -0.2>;
  13. rotation mid_rotation = <0.0, 0.0, 0.0, 1.0>;
  14. vector bot_offset = <0.0, 0.0, -0.2>;
  15. rotation bot_rotation = <0.0, 0.0, 0.0, 1.0>;
  16.  
  17. // Define the leg movement variables
  18. float leg_angle = 0.0;
  19. float leg_speed = 0.0;
  20.  
  21. default
  22. {
  23.     state_entry()
  24.     {
  25.  
  26.         // Position and rotate the leg objects relative to the vehicle object
  27.         vector vehicle_pos = llList2Vector(llGetObjectDetails(vehicle, [OBJECT_POS]), 0);
  28.         rotation vehicle_rot = llList2Rot(llGetObjectDetails(vehicle, [OBJECT_ROT]), 0);
  29.  
  30.         vector top_pos = vehicle_pos + (vehicle_rot * top_offset);
  31.         llSetPos(top_pos);
  32.         llSetRot(vehicle_rot * top_rotation);
  33.  
  34.         vector mid_pos = top_pos + (vehicle_rot * mid_offset);
  35.         llSetLinkPrimitiveParamsFast(llGetLinkNumber(), [PRIM_POSITION, mid_pos, PRIM_ROTATION, vehicle_rot * mid_rotation]);
  36.  
  37.         vector bot_pos = mid_pos + (vehicle_rot * bot_offset);
  38.         llSetLinkPrimitiveParamsFast(llGetLinkNumber(), [PRIM_POSITION, bot_pos, PRIM_ROTATION, vehicle_rot * bot_rotation]);
  39.  
  40.         // Start the leg movement timer
  41.         llSetTimerEvent(0.1);
  42.     }
  43.  
  44.     timer()
  45.     {
  46.         // Get the vehicle velocity and direction
  47.         vector vehicle_vel = llList2Vector(llGetObjectDetails(vehicle, [OBJECT_VELOCITY]), 0);
  48.         vector vehicle_dir = llRot2Fwd(llList2Rot(llGetObjectDetails(vehicle, [OBJECT_ROT]), 0));
  49.  
  50.         // Calculate the leg speed based on the vehicle velocity
  51.         leg_speed = llVecMag(vehicle_vel) * llDot(vehicle_dir, llVecNorm(vehicle_vel));
  52.  
  53.         // Calculate the leg angle based on the leg speed
  54.         leg_angle += leg_speed * 0.01;
  55.  
  56.         // Calculate the leg position and rotation based on the leg angle
  57.         vector bot_pos = llGetPos() + (llGetRot() * bot_offset);
  58.         rotation bot_rot = llGetRot() * bot_rotation * llEuler2Rot(<0.0, 0.0, leg_angle>);
  59.  
  60.         // Update the leg position and rotation
  61.         llSetLinkPrimitiveParamsFast(llGetLinkNumber(), [PRIM_POSITION, bot_pos, PRIM_ROTATION, bot_rot]);
  62.     }
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement