Set speed with llSetRot?
|
|
Rook Inventor
Registered User
Join date: 11 Mar 2009
Posts: 22
|
03-19-2009 18:02
I've looked all over and I can't seem to find if there is a way to set the speed an object rotates with llSetRot. I did find other ways to rotate the object, but llSetRot is simple and works for me. I just wish my dice rolled a little faster.
Any help?
|
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
03-19-2009 21:37
There is no speed for llSetRot(), it just spins at that rate, to modify the rate you'd have to do successive llSetRots with a short delay in between. Both laggy and jerky rotation result from doing that. You're other option would be to use llTargetOmega(), where you can control the speed, but you'd have to manually turn on and off since triggering it starts a continuous rotation.
_____________________
My tutes http://www.youtube.com/johanlaurasia
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
03-19-2009 21:39
setRot is a one time turn, but I'll assume it's being used in a series, to provide the illusion of turning?
faster: use bigger incremental turns, up to 180 degrees (more and you get the back spin vision that you see on RL car wheels)
fastest: one single turn
slower: smaller incremental turns
slowest: incremental turns at the minimum update angle (the smallest angle the viewer will show a change for)... this used to be ~6 degrees but I think the newer view codebase is lower... like ~2-3 degrees? maybe less? could be dependent on size.
ETA: as johan pointed out, larger agles do make for jerkier motion, where smaller ones seem smoother
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Jim Gustafson
Registered User
Join date: 6 Feb 2007
Posts: 84
|
03-20-2009 06:13
For a dice you should use a physical object and apply an rotational impulse to that dice. This is the best way to have a working dice in SL.
Jim
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
03-20-2009 09:48
llLookAt() and llRotLookAt() work for both physical and non-physical objects. You cannot set the axis about which the object will rotate except by using small increments, but you CAN roughly control the time it takes the object to reach the desired orientation. This is an area that actually has very good support. Now if only we had something similar for positional shift of non-physical objects. Or... http://jira.secondlife.com/browse/SVC-3783
|
|
Rook Inventor
Registered User
Join date: 11 Mar 2009
Posts: 22
|
03-20-2009 22:14
Well, I played around with my dice today. The dice rolling is cosmetic. I'm actually generating the roll with a random number generator and displaying the result on the die. Jim, I see what you are saying, but this is a HUD, not actual dice.
Anyway, I got the effect I was looking for with llTargetOmega(). I send the dice gyrating in random directions, then I set a small delay, turn the gyrations off, and then set the final position with llSetRot(). It looks good. I'm only having one problem. If the result of the roll is the same as the previous roll, the die ends up cocked at weird angles. Here's the code. Maybe someone can see something that I'm missing.
integer rollDie(integer dieRoll) { integer x = 0; integer y = 0; integer z = 0; vector rot = <llFrand (3)+1,llFrand (3)+1,llFrand (3)+1>; llTargetOmega(rot, 6.0, 1.0); llSleep(.75); llTargetOmega(ZERO_VECTOR, 0.0, 0.0); if (dieRoll == 1) z = 270; else if (dieRoll == 2) z = 360; else if (dieRoll == 3) y = 270; else if (dieRoll == 4) y = 90; else if (dieRoll == 5) y = 180; else if (dieRoll == 6) z = 90; vector eul = <x,y,z>; eul *= DEG_TO_RAD; rotation quat = llEuler2Rot(eul); llSetRot(quat); return (integer) dieRoll; } default { state_entry() { }
touch_start(integer total_number) { llMessageLinked(LINK_ROOT, 0, "Roll", NULL_KEY); } link_message(integer sender_num, integer num, string str, key id) { integer die = rollDie(num); } }
In the root script, a random number is generated and returned to tell the die where to end up on.
|
|
Rook Inventor
Registered User
Join date: 11 Mar 2009
Posts: 22
|
03-21-2009 05:29
I did some tinkering and thought I had fixed the problem. But I only moved the problem so it is more hidden. Now it will only happen when it rolls a '2' two twice in a roll. The significance of the 2 is just because that happens to be the 0,0,0 position of the die. Still at a loss as to why its doing it though.
Here is the script...
integer rollDie(integer dieRoll) { integer x = 0; integer y = 0; integer z = 0; vector rot = <llFrand (3)+1,llFrand (3)+1,llFrand (3)+1>; llTargetOmega(rot, 6.0, 1.0); if (dieRoll != 2) llSetRot(ZERO_ROTATION); llSleep(.75); llTargetOmega(ZERO_VECTOR, 0.0, 0.0); if (dieRoll == 1) z = 270; else if (dieRoll == 2) z = 0; else if (dieRoll == 3) y = 270; else if (dieRoll == 4) y = 90; else if (dieRoll == 5) y = 180; else if (dieRoll == 6) z = 90; vector eul = <x,y,z>; eul *= DEG_TO_RAD; rotation quat = llEuler2Rot(eul); llSetRot(quat); return (integer) dieRoll; } default { state_entry() { }
touch_start(integer total_number) { llMessageLinked(LINK_ROOT, 0, "Roll", NULL_KEY); integer mem = llGetFreeMemory(); } link_message(integer sender_num, integer num, string str, key id) { integer die = rollDie(num); } }
|
|
Rook Inventor
Registered User
Join date: 11 Mar 2009
Posts: 22
|
03-21-2009 09:40
I got it working! Basically while the die is rolling randomly, I set it to ZERO_ROTATION unless the roll is a '2' then I set it 90 degrees off. That's seems to work. I still don't know why it is doing it, but if it works, it works. Now for the sound effects.
integer rollDie(integer dieRoll) { integer x = 0; integer y = 0; integer z = 0; vector two = <90,0,0>; vector rot = <llFrand (3)+1,llFrand (3)+1,llFrand (3)+1>; if (dieRoll == 1) z = 270; else if (dieRoll == 2) z = 0; else if (dieRoll == 3) y = 270; else if (dieRoll == 4) y = 90; else if (dieRoll == 5) y = 180; else if (dieRoll == 6) z = 90; vector eul = <x,y,z>; two *= DEG_TO_RAD; eul *= DEG_TO_RAD; rotation quat = llEuler2Rot(eul); llTargetOmega(rot, 6.0, 1.0); if (dieRoll != 2) llSetRot(ZERO_ROTATION); else if (dieRoll == 2) llSetRot(llEuler2Rot(two)); llSleep(.75); llTargetOmega(ZERO_VECTOR, 0.0, 0.0); llSetRot(quat); return (integer) dieRoll; } default { state_entry() { }
touch_start(integer total_number) { llMessageLinked(LINK_ROOT, 0, "Roll", NULL_KEY); integer mem = llGetFreeMemory(); } link_message(integer sender_num, integer num, string str, key id) { integer die = rollDie(num); } }
|
|
Irene Pienaar
Registered User
Join date: 13 Oct 2008
Posts: 2
|
03-21-2009 11:43
From: Rook Inventor I've looked all over and I can't seem to find if there is a way to set the speed an object rotates with llSetRot. I did find other ways to rotate the object, but llSetRot is simple and works for me. I just wish my dice rolled a little faster.
Any help? llSetRot is not meant to make an object spin, but to place the object into one rotational state; of course you can repeat the call to suggest spinning, but thats not the best way; use llTargetOmega instead.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
03-21-2009 16:20
I had a dice project where I used physical dice and llApplyRotationImpulse(). Just had to be careful when they hit the ground or they'd fly all over the place and off the edge of the world. Maybe Havok 4 has toned that down a bit. Fun little build. I wound up setting them non-physical after the fun was over and rotating them so a randomly determined side was up as well.
|