Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Getting linked prims to respond to scripts individually

Fearal Cortes
Registered User
Join date: 10 Feb 2007
Posts: 7
07-02-2007 21:12
Hi

I'm in my first simple-medium script-build. I built a ship and before scripting it with the flying commands and etc, I wanted to include some other things. Individually I had already scripted the hatch to swing open and close when you touched it... by making rotate a prim linked to the hatch (the prim that serves as axle is the root prim) where the axle of the swinging would be. Maybe that's just a cheap approach but it's just my first attemp beyond the typical script to change textures and I haven't got hold of the functions yet. Then I made a chair for the ship and I scripted it to rotate at an angle backwards when someone sits on it, again I did this by making a small prim (so that it had its local axles oriented towards the worlds axles) and putting the script on it since the chair is made of a piece of a toroid so it has odd rotation angles, then linking the whole and leaving the small prim as the root prim.

So the problem is..., When I link the chair and the hatch to the whole ship triggering the scripts results in the predictable situation in which the whole thing rotates against the current root prim (If it's one of the prims in which I had the script). And the other case is when the prims I use for axles are not root prims, then they just turn themselves. The most obvious solution for it would be to just put the script on the chair or the hatch, but i don't know how can I make it rotate around a different axle than the one in the center of the prim.

I'm using currently in the scripts the touch and changed events for the touch, sit triggers, and then i just use llSetRot (I tried to use llSetLocalRot but I didn't get quite the hang of it).

thanks in advance :D
Noctua Janus
Registered User
Join date: 22 Mar 2007
Posts: 29
07-03-2007 01:14
To achieve a local rotation you need to divide the local rotation by the rotation of the rootprim (you can query this by calling llGetRootRotation( ))

So your rotation command should look similar to
From: someone

llSetRot( myPrimRotation / llGetRootRotation());


This should work for the hatch, you don't need any additional prims working as an axle to achieve this.

In case of llSetLocalRot you need to multiply your rotation with the root rotation if you want to apply a global rotation to the prim.

In regards to the chair, as I would assume that it is not a one prim chair you would need to rotate / replace every part of it to achieve the correct result while linked with the ship - so it might be easier to leave it unlinked - just select the ship and the chair when taking it to your inventory, it will rez in the correct position again.
Fearal Cortes
Registered User
Join date: 10 Feb 2007
Posts: 7
07-03-2007 20:51
I didn't quite understand what you were saying, you say that by doing this the hatch will be able to rotate on an axle that is not in its center?

Because what I want is for the hatch to open just like a door but upwards, and a door doesn't open by rotating on its center axle, but on an axle on one of its edges.

By the way, I just checked and the chair is made of one prim, a torus.

Another thing by the way, I intend to make the ship physical in order to fly it, so is it good to use llsetrot and this kind of functions? or should I use the ones that act on physical objects? (I could turn it physical as soon as someone sits on it and turn the physical off when the person unsits.
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
07-03-2007 21:20
From: Fearal Cortes
Because what I want is for the hatch to open just like a door but upwards, and a door doesn't open by rotating on its center axle, but on an axle on one of its edges.

To do this, alter the box prim using Path Cut so that it's "center" is on the edge you desire it to rotate about.
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
07-03-2007 21:35
Sadly there is only one root prim in a single linked object. When you link two linked objects together, one of their roots becomes the new root for all. There is no hierarchy.

You could simulate rotation around an external axis by changing local position along with rotation.

It is possible to position/rotate a set of prims around another (non-root) linked prim in the set, you just need to communicate between the parts (each prim to be moved needs a script, as well as the prim serving as axis) so that you can get the "axis" prim's current local position/rotation in the set, and have scripts in each of the prims which needs to move, setting their local position/rotation around that axis prim instead of the root prim.

Alternately, you could define the position/rotation of those child prims relative to the root prim of the entire object, and have them pos/rot themselves around some imaginary local point. That local point would have to be adjusted for the root prim's position/rotation.

I've used both approaches, they both work. Depends on what you need to do, for example if you need multiple copies of the objects linked in (such as multiple linked hatches). Using a local prim to rotate around, each linked copy could use an identical script. Moving relative to the root, you'd have to configure the "imaginary axis point" in each set you link into the whole.

Note: You can change the local position and rotation of a physical object while it's physical, but you cannot change the size/shape while physical. Changing any PRIM_TYPE parameters will immediately unseat any avatars seated on the object. But these should not be problems if you simply wish to rearrange some prims.
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
07-04-2007 04:56
From: Boss Spectre
Alternately, you could define the position/rotation of those child prims relative to the root prim of the entire object, and have them pos/rot themselves around some imaginary local point. That local point would have to be adjusted for the root prim's position/rotation.
This is how the Timeless Linked Door works (/15/58/102144/1.html and somewhere in lslwiki), with a lot of bells (literally) and whistles (figuratively). Also, Deanna's suggestion is very helpful, even if using something like the Timeless Linked Door, because it saves some prim translation steps in the Editor when telling that script the difference between "closed" and "open" orientations. (I generally convert the box to a sphere and chew away at the Dimple, so Path Cut is still available for other mischief after the prim is converted back to a box.)
Fearal Cortes
Registered User
Join date: 10 Feb 2007
Posts: 7
07-04-2007 12:42
Ok then, what I'll end up doing is to rotate the hatch by a combination of setpos and setrot in order to achieve its place and rotation when it's touched, I'll probably do the same with the chair.

My only question now is: is it okay then to use those functions with a physical objetc? Or maybe I can turn it physical after a series of events. for example after the person has opened the hatch, sitted on the ship and closed the hatch?

Thanks for the tips. The dimple one is a very good way to trick the "cutting path" into going around other directions, except this "cutting path" is the dimple "path".
Chaz Longstaff
Registered User
Join date: 11 Oct 2006
Posts: 685
03-30-2008 19:27
Yes, I'm sure the usual "necro poster" bashers will come out, but I just think it's better to keep the thread all together for future searchers to find all in one place so any such bashing in my direction is electrons :}

The script by Qie Niangao works great when in a single prim.

I'm trying to get it to work in a child prim in a link set.

I think the part that is killing me is the prim rotation part below:

llSetLinkPrimitiveParams(newLinkCount,
[ PRIM_POSITION, llList2Vector(sitOffsets, seatNumber)
, PRIM_ROTATION, sitRot / llGetRot()
]);

I'm ending up at all kinds of weird rotations, that don't occur when the prim is a standalone one.

Rotations do me head in.

I've tried various permutations of llGetLocalRot(), but nothing is working, and it's time to yelp for help.

Or, maybe the script just plain won't work in a linked set -- it seems like it does, it's just that you end up sitting upside down 4 feet in the air and a foot or two away.