Rotation of prim attachments
|
|
Virrginia Tombola
Equestrienne
Join date: 10 Nov 2006
Posts: 938
|
02-24-2007 11:55
Hello all! I have made a cycle that is "worn" by the avatar (after the old freebie "safety cycle" that is floating about). I want the wheels to rotate when the avatar moves. Taking my cue from my vehicle style cycles, I went to Aaron Perkin's car script and tried to adapt the "rear wheel" (texture rotation only) script.
rotation Inverse(rotation r) { r.x = -r.x; r.y = -r.y; r.z = -r.z; return r; } rotation GetParentRot() { return Inverse(llGetLocalRot())*llGetRot(); } SetLocalRot(rotation x) { llSetRot(x*Inverse(GetParentRot())); }
default { state_entry() { }
link_message(integer sender_num, integer num, string str, key id) { vector vel = llGetVel(); float speed = llVecMag(vel); if(speed > 0.0) { state driving; } } }
state driving
{ state_entry() { SetLocalRot(llEuler2Rot(<-1 * PI_BY_TWO,0,0> )); llSetTimerEvent(0.5); }
timer() { vector vel = llGetVel(); float speed = llVecMag(vel); llSetTextureAnim(ANIM_ON|LOOP|SMOOTH|ROTATE,ALL_SIDES,0,0,0,0,speed); }
link_message(integer sender_num, integer num, string str, key id) { vector vel = llGetVel(); float speed = llVecMag(vel); if(speed==0) { state default; } } state_exit() { SetLocalRot(llEuler2Rot(<-1 * PI_BY_TWO,0,0> )); llSetTextureAnim(0,ALL_SIDES,0,0,0,0,0); } }
Basically, I tried to enter the "drive" state using this bit of code: vector vel = llGetVel(); float speed = llVecMag(vel); if(speed > 0.0) { state driving; }
Once there, the following should happen: state driving
{ state_entry() { SetLocalRot(llEuler2Rot(<-1 * PI_BY_TWO,0,0> )); llSetTimerEvent(0.5); }
timer() { vector vel = llGetVel(); float speed = llVecMag(vel); llSetTextureAnim(ANIM_ON|LOOP|SMOOTH|ROTATE,ALL_SIDES,0,0,0,0,speed); }
Well, it compiles fine, but I get no texture rotation. Any idea what I'm doing wrong?
|
|
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
|
02-26-2007 16:43
Try: llSetTextureAnim(ANIM_ON | LOOP | SMOOTH | ROTATE, ALL_SIDES, 0, 0, 0, TWO_PI, speed);
|
|
Virrginia Tombola
Equestrienne
Join date: 10 Nov 2006
Posts: 938
|
02-27-2007 07:49
Hum--still no rotation.
I think my problem is defining the drive state. I need to have two clear cut states, one in which the avatar (or the prim attachment I am trying to rotate) is moving, one in which it is not. I'm thinking llGetAgentInfo might be the way to go. If the Agent is walking or flying, it will go to the drive state.
|
|
Virrginia Tombola
Equestrienne
Join date: 10 Nov 2006
Posts: 938
|
02-27-2007 10:33
Well, here's what I came up with. Still no rotation: // check if the agent is flying or walking, then set a royation default { state_entry() { integer i; if (llGetAgentInfo(llGetOwner()) & AGENT_FLYING) { vector vel = llGetVel(); float speed = llVecMag(vel); llSetTextureAnim(ANIM_ON|LOOP|SMOOTH|ROTATE,ALL_SIDES,0,0,0,TWO_PI,speed); } else if (llGetAgentInfo(llGetOwner()) & AGENT_WALKING) { vector vel = llGetVel(); float speed = llVecMag(vel); llSetTextureAnim(ANIM_ON|LOOP|SMOOTH|ROTATE,ALL_SIDES,0,0,0,TWO_PI,speed); } else { llSetTextureAnim (0, 0, 0, 0, 0.0, 0.0, 0.0 ); //If not flying or walking, sets rotation to 0 } } } I also tried it with a basic llSetTextureAnim(ANIM_ON | ROTATE | SMOOTH | LOOP,ALL_SIDES,1,1,0,6,2);
in place of the speed based rotational rate. It didn't work either, which tells me it has something to do with either the logic or my use of llGetAgent Info, since if I just put default { state_entry() { llSetTextureAnim(ANIM_ON | ROTATE | SMOOTH | LOOP,ALL_SIDES,1,1,0,6,2); } }
It rotates just fine. Unfortunately, it's also continuous, which I don't want. More than somewhat confused......
|
|
Ged Larsen
thwarted by quaternions
Join date: 4 Dec 2006
Posts: 294
|
02-27-2007 12:30
Miss Tombola -- Have you tried putting llOwnerSay("In <whichever> event"  ; in various places of your script, to make sure you actually are entering the events that change the texture animations? Sorry I could not be a better help yesterday,
_____________________
- LoopRez, flexi prim skirt generating tool - LinkRez, a necklace chain generator
|
|
Virrginia Tombola
Equestrienne
Join date: 10 Nov 2006
Posts: 938
|
02-27-2007 17:33
Oh, you helped a lot, Mr. Larsen! I was fair clueless about stopping the texture rotation before I asked you about it. (enter a FALSE for the first variable in the argument, for those just tuning in)
I'll have to try the llOwnerSay idea. It seems like a good troubleshooter for states or events (notice I gave up on the states idea?)
|
|
DeepestBlue Luna
Registered User
Join date: 9 Aug 2006
Posts: 13
|
02-28-2007 09:11
Virginia, could you activate a rotating texture for a specific texture i.e. the wheels when you are moving? I am a real dud at scripting, and often use modelling techniques to get round issues like this. Hope it might be of some help.....
|
|
Virrginia Tombola
Equestrienne
Join date: 10 Nov 2006
Posts: 938
|
02-28-2007 12:33
I'm not precisely God's gift to scripting, either, DeepestBlue  The code default { state_entry() { llSetTextureAnim(ANIM_ON | ROTATE | SMOOTH | LOOP,ALL_SIDES,1,1,0,6,2); } }
Rotates the texture nicely (the "rubber" section is black, so all you see is the spokes moving). But I can't just plop that in the prim, as I want it to stop when the rider stops--thus my cursing at these logic issues.
|