|
Trey Harris
Registered User
Join date: 28 Mar 2006
Posts: 8
|
11-22-2006 14:37
Im tryin to make a simple script that makes a snowman spit out a few snowballs. I got it kind of working, but im not real sure about some things. When I rotate the snowman the snowballs no longer come out of his mouth ttey continue to rez in the same dircetion. How do I make the snoballs come stright ut of his mouth enve if he is rotated. See code below, I am very new to this so maybe i am just bitting off more than i can chew  Thanks! vector speed = <0,5,1>; integer max = 10; integer x; default { state_entry() { } link_message(integer sender_num, integer num, string str, key id) { for (x = 0; x < max; x++) { llRezObject("snowup1", llGetPos() + <0, .1, -.05>, speed,llGetRot(), 42); llSleep(.3); } } }
|
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
11-22-2006 16:16
Try: vector speed = <0,5,1>; integer max = 10; integer x; default { state_entry() { } link_message(integer sender_num, integer num, string str, key id) { for (x = 0; x < max; x++) { llRezObject("snowup1", llGetPos() + <0, .1, -.05>*llGetRot(), speed*llGetRot(),llGetRot(), 42); llSleep(.3); } } } Your offset won't be quite right as you turn, and velocity vector remains global. You can be nicer and use rotation rot=llGetRot(); in the line above llRezObject and replace all the llGetRot() bits with rot. You can make your scripts easier to read on this forum by using php and /php in square brackets [ ] to format it as code.
|
|
Trey Harris
Registered User
Join date: 28 Mar 2006
Posts: 8
|
That worked great!!
11-22-2006 20:09
Thanks so much that worked great, not quite sure what it all does. I guess the math behind it is a little over my head. Thanks you!!
|
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
11-23-2006 02:44
I'm not 100% on the details of the maths, but in loose terms:
llGetPos() + <0, .1, -.05>*llGetRot(), speed*llGetRot(),
llGetPos() + <0.0, 0.1, -0.5> defines an offset from the current position. It only works for zero rotation - it's set in terms of the world if you like to think of it that way. Similarly speed gives a vector in terms of x, y, z in the world.
Quaternion rotations, which is what SL uses do two cool things. One is they avoid gimbal lock.
The other is vector * rotation gives you a vector basically the same at the old one at the new orientation in a computationally simple way (for a computer not back on an envelope).
You built your snowman aligned with the world (Prims are rezzed that way, more or less, until we rotate them). So, your offset vector to rez snowballs at the mouth rather than the centre of the snowman worked. Imagine that's like a bar or a ruler (you can do this at home, but probably not in the office for real if you like). One end of the ruler against your belly button, the other end somewhere away from you (makes the turns easier to see). Now turn left. The ruler hasn't changed... but it's position relative to the room has, even though it's position relative to you hasn't, yes?
You don't need to understand all the maths (I don't) to remember that that way to work that out in SL is vector * llGetRot().
Unrotating is /llGetRot() and if you're combining rotations you multiply them or divide them rather than adding or subtracting.
Most of us (possibly all) don't really understand them fully, and work things out by trial and error and remembering what we did wrong, and we mainly avoid them wherever we can, or work out how to work around them.
|