Biran Gould Posted March 1, 2022 Share Posted March 1, 2022 (edited) Hello. I created a script, that lets the avatar flip a coin. You can see a gif of it here https://gyazo.com/e75392a90d9419d76ee0453f46caba0c Its a simple little thing, and i was happy with it. Here's the function in my original script. vector hPos = <0.008243, 0.000406, -0.006726>; vector hRot = <0.0, 0.0, 0.0>; fMove(integer gohome) { if (gohome) { llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_POS_LOCAL, hPos, PRIM_ROT_LOCAL, llEuler2Rot(hRot)]); } else { list p = llGetLinkPrimitiveParams(LINK_THIS, [PRIM_POS_LOCAL, PRIM_ROT_LOCAL]); vector pos = llList2Vector( p,0 ); vector mRot = llRot2Euler(llList2Rot( p,1 )); moved ++; if (moved < 30) { pos.z += 0.01; } else if (moved > 60) { moved = 0; mRot.z = 0; } else if (moved == 30) { pos.z = hPos.z; } else { pos.z -= 0.01; } mRot.x += 0.1; if (pos.z > hPos.z) { pos.z = hPos.z; } llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_POS_LOCAL, pos, PRIM_ROT_LOCAL, llEuler2Rot(mRot)]); } } Full source : https://pastebin.com/190Thxjm The problem arrived, when i got a better animation. Now the default rotation of the coin has changed, and i just can't seem to get it flipping end over end. my second version, which has the following defaults vector hPos = <0.047370, -0.024816, 0.011251>; vector hRot = <0.0, 1.57080, 0.0>; behaves like this https://gyazo.com/711bc5b5e44601b6e5a45bd9fe96bd72 full source https://pastebin.com/JXvwQyTX any help would be appreciated! thank you! Edited March 1, 2022 by Biran Gould improve readability Link to comment Share on other sites More sharing options...
Quistess Alpha Posted March 2, 2022 Share Posted March 2, 2022 You can actually do this with clever use of omegas and a sliced cylinder: // 'coin flip' omega. link 2 prims and run the script once. default { state_entry() { float height = 0.25; // 1/4 the height actually. float diameter = 0.1; float speed = 2.5; llSetLinkPrimitiveParamsFast(1, [ PRIM_OMEGA, <0,1,0>, speed, 1.0, // omega PRIM_COLOR, ALL_SIDES, <1,1,1>, 0.0, PRIM_LINK_TARGET, 2, PRIM_POS_LOCAL, <0,0,height>,PRIM_ROT_LOCAL, <0,0,0,1>, PRIM_SIZE, <diameter,diameter,2*height>, PRIM_TYPE, PRIM_TYPE_CYLINDER, // hole cut hollow twist taper sheer 0, <0,1,0>,0.0,<0,0,0>,<1,1,0>,<0,0,0>, PRIM_SLICE, <0.98,1.0,0>, PRIM_OMEGA, <0,1,0>, -2*speed, 1.0 ]); } } Link to comment Share on other sites More sharing options...
Quistess Alpha Posted March 2, 2022 Share Posted March 2, 2022 Your main problem seems to be you're trying to directly manipulate Eulers. TL;DR Don't do that, ever. I had a play at it. . . set_coin_at_time(float t) { float TIME_FACTOR = 0.5; // # tosses per second. float HEIGHT_MAX = 0.5; float N_FLIPS = 2.0; // can make negative to flip other direction. float FLIP_PHASE = 0.0; // if not flat in the hand, change this between 0 and 1. integer LINK_NUMBER = 2; t = TIME_FACTOR*t; // normalize time slower or faster. t = t-(integer)t; // restrict t to range [0,1) float height = HEIGHT_MAX*(1-(4*(t-.5)*(t-.5))); // parabolic arc with zeros at 0 and 1. float angle = (t+FLIP_PHASE)*TWO_PI; // x-axis rotation. for y or z axis, swap the llSin() with one of the 0's. rotation rot = <llSin(0.5*angle),0,0,llCos(0.5*angle)>; llSetLinkPrimitiveParamsFast(2, [ PRIM_ROT_LOCAL, rot, PRIM_POS_LOCAL, <0,0,height> ]); } default { state_entry() { llSay(0, "Hello, Avatar!"); llSetTimerEvent(0.05); } timer() { set_coin_at_time(llGetTime()); } } Link to comment Share on other sites More sharing options...
Biran Gould Posted March 2, 2022 Author Share Posted March 2, 2022 Thanks Tessa! i'll look into it. 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