General Question - Animating individual parts?
|
|
a lost user
Join date: ?
Posts: ?
|
08-28-2005 11:05
My question is at the general/conceptual level - I'm not looking for specific scripts or detailed "how to" answers.
Problem Statement: Assume I have a box with a lid. I want the lid to swingopen when someone touches it. Also, when the lid opens I want a a ball to bounce out.
1st Issue: Is there a way to have the lid open (i.e. rotate on a hinge) if it is linked to the box?
In my testing of this so far, I believe it's not possible. I've succeed in having the lid linked to an object (aka like hinge) and the lid opens when touched. However, when I link it all together, the entire box rotates as well.
2nd Issue: If the lid can not be linked to the box, then it becomes problematic trying to move the entire object. Often the box ends up getting moved and the lid remains behind, etc.
Also, if the items are not linked - how could that object be sold to someone and rezzed together? (with the lid positioned properly with respect to the box)
3rd Issue: May not be a separate issue, as the answers to the above questions may resolve this one, how do you have the ball "appear" or bounce out?
Again - I am not looking for someone to provide exact code to answer the above questions, merely trying to get my arms around what needs to be done conceptually.
|
|
Foolish Frost
Grand Technomancer
Join date: 7 Mar 2005
Posts: 1,433
|
08-28-2005 11:13
1- Yes. Easy answer: cut the prim into 1/4 so that the center-of-gravity the prim is at the edge corner of one side of the prim. Just like you do for single prim doors.
2- When you link the lid to the rest of the box, make sure the LAST PRIM you select before linking is NOT the part you will be moving. Then you put a llSetLocalRot script into the PRIM that you want to rotate (the lid, in this case).
3- Have it rez the ball, and have the ball scripted to bounce away. This is not only physics, but beyond the basics of the main discussion. Just suffice it to say the ball is in the contents of the box and that the box rezzes the ball while opening.
Anything else?
|
|
a lost user
Join date: ?
Posts: ?
|
Appreciate the Advice
08-28-2005 11:21
Foolish Frost - Thanks for the quick reply.
I've heard others mention this "single prim door" concept but I've not yet seen one. The door I have uses 2 prims (door and hinge) and that's the exampled I modeled my box top on. Your method sounds more efficient as I'll not need the extra (hinge) item for the lid to rotate around.
|
|
Foolish Frost
Grand Technomancer
Join date: 7 Mar 2005
Posts: 1,433
|
08-28-2005 11:27
From: Alendril Mullen Foolish Frost - Thanks for the quick reply.
I've heard others mention this "single prim door" concept but I've not yet seen one. The door I have uses 2 prims (door and hinge) and that's the exampled I modeled my box top on. Your method sounds more efficient as I'll not need the extra (hinge) item for the lid to rotate around. You use a cube, and use the rotation cut to only keep 1/4 of it. When you look at the prim, to movement grabbers will be to one edge of the prim then. That is the point of the hinge, and all you have to figure out is the rotation needed to make it open properly.
|
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
08-28-2005 12:00
The door and hinge approach won't work here, rotating the hinge with a localrot script will do just what it says and rotate the hinge.
Try 0.375 and 0.875 for your cut...
|
|
Salma Isbell
Registered User
Join date: 10 Jun 2006
Posts: 16
|
another single prim door approach
09-12-2006 05:28
You can also use the drop down menu in the editor to convert your door into a sphere instead of a box, then use the dimple property to remove half of the door, then change it back into a box and the missing half remains gone.
|
|
Rich Cordeaux
Registered User
Join date: 8 May 2006
Posts: 26
|
09-12-2006 09:48
Rotation around an arbitrary point is quite doable. There are various functions for this posted on these forums and in the scripting wiki, if you search, but after looking at them and noting that they were all different, I just wrote my own instead (which also came out quite different). I haven't posted mine, but it's rather more complicated and powerful (See this post). It's also rather much overkill for what you want. You could instead do this: 1) record your door's position and rotation in the closed position, 2) record your door's position and rotation in the open position, 3) make a simple script to interpolate between the two and call llSetPrimitiveParams. Here's an example of a very simple script to interpolate between two positions+rotations: float doorStep=1.0;
vector closedRot; vector openRot; vector diffRot;
vector closedPos; vector openPos; vector diffPos;
updateRot() { //0.99 is open, and 0 is closed. vector vecRot = diffRot*doorStep + closedRot; vector vecPos = diffPos*doorStep + closedPos; llSetPrimitiveParams([PRIM_POSITION, vecPos, PRIM_ROTATION, llEuler2Rot(vecRot)/llGetRootRotation()]); }
default { state_entry() { closedRot = <90.0, 0, 270.0>*DEG_TO_RAD; closedPos = <0,0,0>; openRot = <90.0, 0, 199.0>*DEG_TO_RAD; openPos = <-1.573,0,0.563>; diffRot = (openRot - closedRot); diffPos = (openPos - closedPos); } on_rez(integer param) { doorStep=0.0; updateRot(); } }
And change doorStep and call updateRot() in a timer when the lid should be opening or closing. You'll need to change the closed and open position and rotation to fit your lid, of course. That isn't perfect, but like I said, it's real simple and something more complicated would be overkill for a single rotating prim.
|
|
Lazink Maeterlinck
Registered User
Join date: 8 Nov 2005
Posts: 332
|
09-12-2006 15:04
Another way to rotate around a point is to use trig identities and the handy llSin and llCos functions. With some simple trig, you can get the offsets of the original point. If your not familiar with trig identities, http://mathforum.org/dr.math/faq/formulas/faq.trig.html will prvide you with all you need to know. Many options out there on how you can do this, this is just one that is a little math heavy, but it works well.
|
|
ed44 Gupte
Explorer (Retired)
Join date: 7 Oct 2005
Posts: 638
|
09-12-2006 21:27
Hi Alendril I posted a very simple door script here: /15/f4/135162/1.htmlAs listed it is not suitable for linked doors. You would need to instruct your buyers to have edit open when they rezzed the lid and the box, or position both seperately to make a pair. However, you can link prims, such as a door knob, to the moving door to move with it. It will start its rotation from whatever position is started in. The rotation parameters are prescribed in the door's description field and starting the action makes allowance for the lid's current rotation. The only proviso being that it should not be moved in the open postion since it stores (each time before it moves) the closed position and rotation also in the description field so as not to allow the door to "walk" due to round off errors. Hope that all makes sense. Rotations have a way of addling the brain!! Ed
|
|
Sue Stonebender
Piano Craftsman
Join date: 7 Jan 2005
Posts: 219
|
Nice, simple rotation script and it can be linked to the parent
09-15-2006 17:15
Here's a nice simple script that you can pop into a child prim that you wish to rotate. Go ahead and link it to the main primset. It doesn't require a prim hinge, nor does it need to be unlinked. It gives a nice, smooth rotation from the first target through to the second. All you have to change is the top code. The first line asks you to identify what the prim's rotation will be relative to the parent prim when it's open. If the parent is set to <0,0,0> then you just take a peek at the prim you're rotating to see what the rot is when you've got it set to where you would want it to be in the open position (otherwise, adjust according to the parent). Similarly, the line below asks you what the rotation should be when this prim is in the closed state, again relative to the parent prim's rotation. The third statement allows you to indicate whether or not this prim should be in the open or closed state when the object it's attached to is first rezzed. If this is a cupboard with handles, you'll need to pass a linked message in so that they can talk to each other and each will know when the other's been touched so that their open and closed states are in synch. This is a staple in my own library. Couldn't do without it. vector r_open = <0.0, 90.0, 0.0>; // This prim's rotations in degrees relative to root prim when this prim is open vector r_closed = <0.0, 0.0, 0.0>; // and when it's in the closed state
integer close_on_rez = TRUE; // Change to false to have the prim open on rez
// ======================================================= Nothing from here down needs modding.
rotation LocalRot(rotation localrot) { rotation LocRot = localrot / ( (ZERO_ROTATION / llGetLocalRot()) * llGetRot()); return LocRot; }
open(string door) { llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(r_open * DEG_TO_RAD))]); }
close(string door) { llSetPrimitiveParams([PRIM_ROTATION, LocalRot(llEuler2Rot(r_closed * DEG_TO_RAD))]); }
default { state_entry() { if (close_on_rez) { state closed; } else { state opened; } } on_rez(integer rez) { llResetScript(); } }
state opened { state_entry() { open("left"); } on_rez(integer rez) { llResetScript(); } touch_start(integer n) { state closed; } }
state closed { state_entry() { close("left"); } on_rez(integer rez) { llResetScript(); } touch_start(integer n) { state opened; } }
Lovely if you're using a nice round lid on a chest. If you're using it as a door and you want it to rotate around the axis, be sure to cut a box prim's path to begin at 0.375 and end at 0.875 as mentioned in an earlier posting above. This gives the illusion of the door rotating at it's edge, rather than in it's center of gravity. Remember, this is just an example. You will have to change the vectors to match the rotations you want for the prim you are using relative to it's own parent. Cheers Sue.
|