Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Fun With Rotations and Targets!

Burke Prefect
Cafe Owner, Superhero
Join date: 29 Oct 2004
Posts: 2,785
03-27-2006 12:44
The Setup: A stationary turret with a moving 'barrel' prim.
Problem: I suck at rots and targets.
What I need: A way for the barrel to look at the called target (if given a position or scanning on it's own?). Moving child prims like this is tricky.
Yes. I'll pay L$500 for this too. :D

It needs to:
- take a position or key as suppied by a control script
- look at the position or key (this is a child prim)

I know. it might not sound that hard, but it is for me.


Thanks, Burke.
_____________________
Zodiakos Absolute
With a a dash of lemon.
Join date: 6 Jun 2005
Posts: 282
03-28-2006 00:33
I believe there is an easier way to accomplish what you are trying to do.

Use two objects. One for the aesthetic turret, and another object for the part of the gun you want to move around (in this sense, object means collection of prims). The actual turret part should be constructed unusually, with the root prim's Z AXIS rotated sideways (so that the z axis is where the X AXIS would normally be).

Then, the scripting command you want is here: http://secondlife.com/badgeo/wakka.php?wakka=llLookAt

llLookAt will align the Z AXIS of the object (physical OR non-physical) to point at a LOCATION vector you specify. You don't have to do this math - if you are using a sensor to pick up targets, simply specify llDetectedPos() as the location to target. The turret will then point in that direction.

If you want to build the turret on a normal axis, there's also a code snippet there on the wiki that can be used for pointing a different axis in the direction you specify.

If you want to fire a weapon from the rotation that the turret is pointed in, you may also be interested in the llGetRot() function, which gets the current rotation of the object the script is in, which can be passed to a bullet or other weapon, as needed. Note that this must be called from a script in the root prim of the object, I believe.
Burke Prefect
Cafe Owner, Superhero
Join date: 29 Oct 2004
Posts: 2,785
03-28-2006 08:55
Actually. That's what I'm doing right now. In the style of the Half-Life 1 turret (ie. a small gun on a tripod). but I wanted the option to make a one-solid object that would lookat with just the barrel.
_____________________
Feynt Mistral
Registered User
Join date: 24 Sep 2005
Posts: 551
03-28-2006 12:17
So at present the whole gun turns, but what you really want is just for the barrel to turn? Is the barrel itself the root prim, or have you tried changing the root to some other prim and gotten odd results from having the barrel as a child? It seems to me the best way to get it to respond the way you want is to either seperate the barrel from the turret mount, or make it into a child prim so rotation and position changes to it do not affect the rest of the turret.

If your gun barrel is more complex than one prim, that unfortunately means simultaneous llSetPos/llSetRot scripts to get it to move with the barrel and the usage of link messages. In this case I would suggest making the barrel a seperate entity to save yourself a headache. Unlink the barrel prims during use (linking them back together with each other, but not the turret prims) and then relink the barrel to the turret after you're done using it.
_____________________
I dream of a better tomorrow in SL!
You should too. Visit, vote, voice opinions.
Support CSG! Tell LL how much it would mean to subtract one prim from another!
Prim Animation! Stop by and say something about it, show your support!
Burke Prefect
Cafe Owner, Superhero
Join date: 29 Oct 2004
Posts: 2,785
03-28-2006 13:02
I'm working on two kinds of turrets. This pertains to the smaller one. It looks like thos

[SENSOR]
[PRIM]
[PRIM][BARREL]
[PRIM]
[PRIM]
[ROOT]

I want the barrel to rotate so it's Z axis is looking at the target. This is the tricky part of the whole operation. In fact it's the only real headache I'm having that's keeping me from getting it 'out to the field'. The turret is guided by sensor and programmed behavior, and operates independant of the owner.

:D
_____________________
Zodiakos Absolute
With a a dash of lemon.
Join date: 6 Jun 2005
Posts: 282
03-28-2006 20:25
I just wouldn't bother with doing it that way myself, there doesn't seem to be any gain for doing so. If you are worried about it breaking apart when a user rezzes/deletes it, simply have the 'base' part of the turret rez the barrel object when in use, and have the barrel do some sort of check to see if the base is gone, and also make it die when the base dies.
Sean Martin
Yesnomaybe.
Join date: 13 Sep 2005
Posts: 584
03-29-2006 00:57
I'm not sure what use this might be but I'll throw it out here.
I use something like this to set positions of linked prims in ships. Only I have not tried the rotation part of it yet.
I would assume it to be very similar though.

I am just using myXrotation, myYrotation, myZrotation for the vector.

eh I'll just throw the code and see what comes of it.
CODE
                       if(message=="set rotation")
{
llSetPrimitiveParams([
PRIM_POSITION,<0.00000, 0.00000, 0.00000>,PRIM_ROTATION,<myXrotation, myYrotation, myZrotation, 1.00000> / ( (ZERO_ROTATION / llGetLocalRot()) * llGetRot())]);
}

This code above just rotates one prim within the linked set to whatever the, "myXrotation" etc, variable is set to. (It's placed inside a linked prim other than the root)


This code below I got from someone once to show me how to face North, South, East or West on demand.
I pulled this part out of the "Face North" section of one of my ships. But really it just makes it face 45 degrees. I think that all depends on the roots current postion? I'm not sure. I think 45 is what faced north for me so I used it. I can't remember.

In any case I would guess somehow linking the code above, with the code below, would be how it works. Somehow. lol
Oh the comments in the code are not mine by the way. :p

CODE
vector eul = <0, 0, 90>; //45 degrees around the z-axis, in Euler form.
eul *= DEG_TO_RAD; //convert to radians.
rotation quat = llEuler2Rot(eul); //convert to quaternion.
llSetRot(quat); //rotate the object


Maybe someone else could put this together somehow? I hate it when I can just about see something fit together but can't get the darn thing to snap right. lol :rolleyes:

:addition:
I'm assuming this part:
llSetRot(quat);
Is where we would work in the:
llSetPrimitiveParams([

hmm I wonder if something like this would work using the quat from the llSetRot(quat)?:
CODE

vector eul = <0, 0, 90>; //45 degrees around the z-axis, in Euler form.
eul *= DEG_TO_RAD; //convert to radians.
rotation quat = llEuler2Rot(eul); //convert to quaternion.
llSetPrimitiveParams([
PRIM_POSITION,<0.00000, 0.00000, 0.00000>,PRIM_ROTATION,<quat> / ( (ZERO_ROTATION / llGetLocalRot()) * llGetRot())]);


Or some evil magic like that maybe? :confused:
:) I dunno.
Obviously none of that will compile because it needs fitting into the main script.
But if it blows up don't look at me. :eek:
_____________________