prootoxy Posted June 5, 2023 Share Posted June 5, 2023 Hello friends how are you??? I've been stuck for hours on a problem and I would like to know if someone could help me... I need to create a car wheel, this wheel needs to rotate and turn left or right while rotating. But when I do both things together (Rotate the wheel and turn it to one side) it doesn't stay on a correct axis. I've spent hours reading the documentation, trying to understand and I really couldn't, I'd like to know if it's possible for someone to help me with this, I'll leave some examples below. How i would like to simulate: How it looks normally when I don't turn it to one side, but I turn it normally at a 90 degree angle to the Z axis: How it looks when I rotate it at a 70 degree angle on the Z axis (to simulate turning right) Link to comment Share on other sites More sharing options...
Quistess Alpha Posted June 6, 2023 Share Posted June 6, 2023 (edited) A) all of your images are 404- not found. B) Doing anything with rotations is very dependent on the specific 'intrinsic orientation' of your wheels and the main body of the thing they're attached to. snipping the relevant portion from the last time I did this (this was added to someone else's code so the variable names are a bit different than my usual style) : // Wheel link numbers integer leftfrontwheel = 11; integer rightfrontwheel = 4; integer leftbackwheel = 15; integer rightbackwheel = 14; // Wheel axis vector wheelaxis = <1,0,0>; // for rotating vector wheelup = <0,0,1>; // for turning left/right rotation wheelBaseRot = <0,0,0.71,0.71>; // initial rotation of the wheel. // Wheel current status float turnAngle = 0.0; // radians; float forwardAngle = 0.0; // radians; // Wheel spin speed float spinspeedback = -0.025; float spinspeedforward = 0.05; float turnSpeed = 0.02; float turnAngleMax = 0.45; // maximum angle left or right. turnWheels(float lr, integer forward) { if(turnAngle<lr) turnAngle += turnSpeed; if(turnAngle>lr) turnAngle -= turnSpeed; if(forward==1) { forwardAngle += spinspeedforward; if(forwardAngle>TWO_PI) forwardAngle-=TWO_PI; }else if(forward==-1) { forwardAngle += spinspeedback; if(forwardAngle<0) forwardAngle+=TWO_PI; } llSetLinkPrimitiveParamsFast( leftfrontwheel,[PRIM_ROT_LOCAL, llAxisAngle2Rot(wheelaxis,forwardAngle)*llAxisAngle2Rot(wheelup,turnAngle)*wheelBaseRot, PRIM_LINK_TARGET, rightfrontwheel,PRIM_ROT_LOCAL, llAxisAngle2Rot(wheelaxis,forwardAngle)*llAxisAngle2Rot(wheelup,turnAngle)*wheelBaseRot, PRIM_LINK_TARGET, leftbackwheel, PRIM_ROT_LOCAL, llAxisAngle2Rot(wheelaxis,forwardAngle)*llAxisAngle2Rot(wheelup,-turnAngle)*wheelBaseRot, PRIM_LINK_TARGET, rightbackwheel, PRIM_ROT_LOCAL, llAxisAngle2Rot(wheelaxis,forwardAngle)*llAxisAngle2Rot(wheelup,-turnAngle)*wheelBaseRot]); } That's a lot of boiler-plate; the basic idea is you need to keep track of 3 rotation variables: 1) the rotation when the wheel is in its initial 'default' position 2) the rotation that makes the wheel roll forward (or backwards) 3) the rotation that makes the wheel turn left and right. you then set the PRIM_ROT_LOCAL of the wheel to 2) * 3) * 1) . That was for a specific mesh wheel; for a standard prim cylinder the relevant parameters are: vector wheelaxis = <0,0,1>; // for rotating vector wheelup = <1,0,0>; // for turning left/right rotation wheelBaseRot = //<0.0,0.71,0.0,0.71>; // y-forward. <-0.5,0.5,0.5,0.5>; // x-forward. Edited June 6, 2023 by Quistess Alpha 1 Link to comment Share on other sites More sharing options...
Quistess Alpha Posted June 6, 2023 Share Posted June 6, 2023 Bigger idea is that to set the orientation of an object in-world, one of the most useful paradigms to keep in mind is that orientation*change causes a change based on global axes, but change*orientation causes a change based on local axes. Consider: rotation r; default { state_entry() { r = llAxisAngle2Rot(<0,0,1>,15*DEG_TO_RAD); // 15 degree rotation about z axis. llSetRot(<llFrand(1.0),llFrand(1.0),llFrand(1.0),llFrand(1.0)>); // randomize orientation. } touch_start(integer total_number) { // use one of the following: llSetRot(llGetRot()*r); // global rotation //llSetRot(r*llGetRot()); // local rotation } } 1 Link to comment Share on other sites More sharing options...
animats Posted June 6, 2023 Share Posted June 6, 2023 Wheels should be spun with llTargetOmega. Then the viewer does the work. If you spin wheels by setting the rotation, it takes many extra object updates and motion will not be as smooth. Possibly useful code: https://github.com/John-Nagle/l*****ils/blob/master/motorcycle/rotatewheel.lsl 3 1 Link to comment Share on other sites More sharing options...
Love Zhaoying Posted June 6, 2023 Share Posted June 6, 2023 14 minutes ago, animats said: Wheels should be spun with llTargetOmega. Then the viewer does the work. If you spin wheels by setting the rotation, it takes many extra object updates and motion will not be as smooth. Possibly useful code: https://github.com/John-Nagle/l*****ils/blob/master/motorcycle/rotatewheel.lsl I had to click on the link to learn, "LSL Utils" is redacted! 2 2 Link to comment Share on other sites More sharing options...
prootoxy Posted June 6, 2023 Author Share Posted June 6, 2023 You don't know how much you've just helped me, thank you so much!! 1 Link to comment Share on other sites More sharing options...
Quistess Alpha Posted June 6, 2023 Share Posted June 6, 2023 (edited) 11 hours ago, animats said: If you spin wheels by setting the rotation, it takes many extra object updates and motion will not be as smooth. True, but Omega for rolling might behave oddly when combined with left and right 'turning' which requires directly setting the rotation in any case. I might give it a test next I get in-world though. ETA: Making Omega and turning work together is non-trivial. The main issues to grapple with are that Omega's axis parameter is in the coordinate space of the root prim; setting the rotation while omega is active continues to rotate in object-local coordinates which leads to wobble; setting both the rotation and omega at the same time can lead to the spin of the wheel jumping back to zero (the wheel 'stops spinning' while it's turning left or right) All of those issues are manageable, but not easy to work around if you don't have a decent understanding of rotations. see: Edited June 6, 2023 by Quistess Alpha Link to comment Share on other sites More sharing options...
Recommended Posts
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