Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Turret or possible rotation script

Mechrior Voyager
Registered User
Join date: 6 Jul 2007
Posts: 7
01-12-2009 15:44
Hi all i am relitively new to LSL and am trying to get to grips with scripting but atm I am trying to make a scripted turret from several parts.... I want the main barrel's to only move up and down and only the base to turn left and right but I want to keep them as one item or possibly have the base rez the turret when put down....

Any help would be GREATLY appreciated.....

MSG me ingame if you prefer or can help.......

Thank you in advance everyone!
Winter Seale
Registered User
Join date: 27 Dec 2006
Posts: 30
01-12-2009 16:22
Well, what you want to do is certainly doable. =p But you didn't actually ask any questions so it makes it hard to answer.

A couple of things though...

If you're set on having the turret as part of the same linkset then, I think, the easiest way would be to have different tourets for each vertical position and just set all but the current position invisible.

If instead you want to rez the turret then things are a little trickier since you'll have to communicate rotation via whispers from the base and they may not animate together totally smoothly. On the other hand, you don't have to work out all the turret's vertical positions in advance.

PS I'm happy to chat in game if you prefer, but the community gains a lot more of discussion happens here.
Mechrior Voyager
Registered User
Join date: 6 Jul 2007
Posts: 7
01-12-2009 16:33
Hi there winter.....

i think i didnt make myself quite clear.... I would like to creat a turret for the vice combat system that allows you to sit in it and take control so the actual gun itself would need to rotate to follow the mouse aim view.....

I am trying to find the simplest way to only allow the actual barrel of the turret to move up and down and only the base turn left and right.....

EDIT MKI:

the current script I am using is this:

[PHP
]key toucher;
string toucherS;
float SPEED = 40.0;
integer LIFETIME = 7;
float DELAY = 0.2;
vector vel;
vector pos;
rotation rot;
integer in_use;
integer have_permissions = FALSE;
integer armed = TRUE;
fire()
{

}
default
{
state_entry()
{
in_use = FALSE;
}
touch_start(integer total_number)
{
if(in_use == FALSE)
{
toucher = llDetectedKey(0);
llRequestPermissions(toucher, PERMISSION_TAKE_CONTROLS|PERMISSION_TRIGGER_ANIMATION);
llSetText("Requesting Permissions", <1,1,1>, 1);
}
if(in_use == TRUE)
{
if(llDetectedKey(0) == toucher)
{
llReleaseControls();
llSensorRemove();
llSetRot(<-0.00000, -0.00000, 0.70711, 0.70711>;);
llSetText("", <1,1,1>, 1);
in_use = FALSE;
}
}
}
sensor(integer sense)
{
rotation k = llDetectedRot(0);
llRotLookAt(k, .1, .1);
}
no_sensor()
{
llReleaseControls();
llSensorRemove();
llSetRot(<-0.00000, -0.00000, 0.70711, 0.70711>;);
llSetText("", <1,1,1>, 1);
in_use = FALSE;
}
run_time_permissions(integer perm)
{
if(perm)
{
llSetText("", <1,1,1>, 1);
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
llSensorRepeat("", toucher, AGENT, 20, TWO_PI, .1);
llSetText("Current User: "+llKey2Name(toucher), <1,1,1>, 1);
in_use = TRUE;
}
else
{
in_use = FALSE;
llSetText("", <1,3,1>, 1);
}
}
control(key name, integer levels, integer edges)
{
if ((levels & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON)
{
fire();
}
}

}

[/PHP]

the only thing is that when i sit on the turret model i have made it starts acting wildly out of function and spins all over the place..... the fire portion of the script will be filled once i know how to add the vice control scripts
Winter Seale
Registered User
Join date: 27 Dec 2006
Posts: 30
01-12-2009 17:29
[Edit: Here's your script inside
CODE
 tags so those of us using the Greasemonkey Userscript can see your indentation.]

CODE
key toucher;
string toucherS;
float SPEED = 40.0;
integer LIFETIME = 7;
float DELAY = 0.2;
vector vel;
vector pos;
rotation rot;
integer in_use;
integer have_permissions = FALSE;
integer armed = TRUE;
fire()
{

}
default
{
state_entry()
{
in_use = FALSE;
}
touch_start(integer total_number)
{
if(in_use == FALSE)
{
toucher = llDetectedKey(0);
llRequestPermissions(toucher, PERMISSION_TAKE_CONTROLS|PERMISSION_TRIGGER_ANIMATION);
llSetText("Requesting Permissions", <1,1,1>, 1);
}
if(in_use == TRUE)
{
if(llDetectedKey(0) == toucher)
{
llReleaseControls();
llSensorRemove();
llSetRot(<-0.00000, -0.00000, 0.70711, 0.70711>);
llSetText("", <1,1,1>, 1);
in_use = FALSE;
}
}
}
sensor(integer sense)
{
rotation k = llDetectedRot(0);
llRotLookAt(k, .1, .1);
}
no_sensor()
{
llReleaseControls();
llSensorRemove();
llSetRot(<-0.00000, -0.00000, 0.70711, 0.70711>);
llSetText("", <1,1,1>, 1);
in_use = FALSE;
}
run_time_permissions(integer perm)
{
if(perm)
{
llSetText("", <1,1,1>, 1);
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
llSensorRepeat("", toucher, AGENT, 20, TWO_PI, .1);
llSetText("Current User: "+llKey2Name(toucher), <1,1,1>, 1);
in_use = TRUE;
}
else
{
in_use = FALSE;
llSetText("", <1,3,1>, 1);
}
}
control(key name, integer levels, integer edges)
{
if ((levels & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON)
{
fire();
}
}

}
_____________________
~~ Winter Seale ~~ http://winterseale.com/ ~~
Mechrior Voyager
Registered User
Join date: 6 Jul 2007
Posts: 7
01-12-2009 17:41
thanks for adding the php tags.....

does that make it easier to see what i need to do.... I need to sleep now as its 2am but I will check back here first thing in the morning.
Winter Seale
Registered User
Join date: 27 Dec 2006
Posts: 30
01-12-2009 17:56
[Edit: I wrote the stuff below and then saw that you're using llRotLookAt, which I would think would be better suited to physical objects. You're also not calling llStopRotLookAt, which you really should do.]

There are a few caveats on the wiki that might be biting you:

From llSetRot
From: someone
If the prim is not the root prim it is offset by the roots local rotation. The work-around is to divide the rotation by the root rotation.
* If you are trying to set the rotation of a child prim relative to the root prim then divide the local rotation by the root rotation.
* If you are trying to set the rotation of a child prim to a global rotation then you need to divide the global rotation by the root rotation twice.
* It is better to use llSetLocalRot to set the rotation of child prims, even if you are setting it to a global rotation (just multiply by the root rotation in that case).
* There is no easy way to get the roots local rotation of an attached object (other then being told by the root).


In particular, the rotation of llDetectedRot is gonna be in global terms so you'll have to do one of the conversions above if you're not acting on the root prim.
_____________________
~~ Winter Seale ~~ http://winterseale.com/ ~~
Mechrior Voyager
Registered User
Join date: 6 Jul 2007
Posts: 7
01-13-2009 01:21
This script is going into the root prim and seems to work fine so far until I try and sit on the object.... then it goes berserk and starts flipping around wildly.

also if my avatar is even slightly off centre before i enter mouselook then the whole thing starts turning.

Im looking into the llStopLookAt now because I couldnt find anything on llStopRotLookAt.
Winter Seale
Registered User
Join date: 27 Dec 2006
Posts: 30
01-13-2009 10:41
Ah, yeah, llStopLookAt() is what I meant. You talk about sitting but your code has nothing that talks about that... it makes more sense for what you're doing.

Have you tried using llOwnerSay to see what values you're getting from your sensor? I'm a bit curiuos if you really show up as rotating at all (mouselook or otherwise) once you're seated, since from the outside you wouldn't look to be moving.

Oh hey, another question... are you sitting on the thing that's rotating? That might explain your crazy rotation... I mean it rotate's to match your view, which turns you, which causes it rotate more to match your view, and so on.
_____________________
~~ Winter Seale ~~ http://winterseale.com/ ~~
Mechrior Voyager
Registered User
Join date: 6 Jul 2007
Posts: 7
01-13-2009 10:46
From: Winter Seale
I'm a bit curiuos if you really show up as rotating at all (mouselook or otherwise) once you're seated, since from the outside you wouldn't look to be moving.

I will have to ask someone else to stand around me for a second to see if i rotate with it at all but i understand slightly what you mean now with regards to the sitting and rotating.


From: Winter Seale
Oh hey, another question... are you sitting on the thing that's rotating? That might explain your crazy rotation... I mean it rotate's to match your view, which turns you, which causes it rotate more to match your view, and so on.

I have tried sititng on the rotating prim and other prims linked to it with some interesting results..... it there another way to be seated mear the turret?
Winter Seale
Registered User
Join date: 27 Dec 2006
Posts: 30
01-13-2009 10:51
From: Mechrior Voyager
I have tried sititng on the rotating prim and other prims linked to it with some interesting results..... it there another way to be seated mear the turret?

Well, you could make the seat be a prim that isn't linked to the turret...
_____________________
~~ Winter Seale ~~ http://winterseale.com/ ~~
Mechrior Voyager
Registered User
Join date: 6 Jul 2007
Posts: 7
01-13-2009 10:52
From: Winter Seale
Well, you could make the seat be a prim that isn't linked to the turret...


how would i get the seat to rotate with the turret?!

just change the script to one axis only?
Mechrior Voyager
Registered User
Join date: 6 Jul 2007
Posts: 7
01-13-2009 11:22
ok so this is the new version of the script but for some reason the actual part that takes control of the mouse button does not seem to function

CODE

key toucher;
string toucherS;
string HUDtext="";
vector HUDcolor;
float SPEED = 40.0;
integer LIFETIME = 7;
float DELAY = 0.2;
vector vel;
vector pos;
rotation rot;
integer in_use;
integer have_permissions = FALSE;
integer armed = TRUE;
integer levels;
//combat system
integer vice_on;
integer dead=FALSE;
integer team;
integer vice_hp;
integer max_vice_hp=10;
// interface Stuff
integer set_private_channel_number;
integer set_private_channel_handle;
integer privatelisten;
integer public_channel_handle;

default
{
state_entry()
{
in_use = FALSE;
key owner = llGetOwner();
llListen(0,"",owner,"");
}
touch_start(integer total_number)
{
if(in_use == FALSE)
{
toucher = llDetectedKey(0);
llRequestPermissions(toucher, PERMISSION_TAKE_CONTROLS|PERMISSION_TRIGGER_ANIMATION);
llSetText("Requesting Permissions", <1,1,1>, 1);
llMessageLinked (LINK_SET,1,"seated",toucher);
}
if(in_use == TRUE)
{
if(llDetectedKey(0) == toucher)
{
llReleaseControls();
llSensorRemove();
llSetRot(<-0.00000, -0.00000, 0.70711, 0.70711>);
llSetText("", <1,1,1>, 1);
llMessageLinked (LINK_SET,0,"seated","");
in_use = FALSE;
}
}
}
sensor(integer sense)
{
rotation k = llDetectedRot(0);
llRotLookAt(k, .1, .1);
}
no_sensor()
{
llReleaseControls();
llSensorRemove();
llSetRot(<-0.00000, -0.00000, 0.70711, 0.70711>);
llSetText("", <1,1,1>, 1);
in_use = FALSE;
}
run_time_permissions(integer perm)
{
if(perm)
{
llSetText("", <1,1,1>, 1);
llTakeControls(CONTROL_ML_LBUTTON | CONTROL_LBUTTON, TRUE, FALSE);
llSensorRepeat("", toucher, AGENT, 20, TWO_PI, .1);
llSetText("Current User: "+llKey2Name(toucher), <1,1,1>, 1);
in_use = TRUE;
}
else
{
in_use = FALSE;
llSetText("", <1,3,1>, 1);
}
}

listen(integer channel, string name, key id, string message)
{
if (message == "vice on")
llMessageLinked(LINK_SET, 1, "vice ctrl", "");
else if (message == "vice off")
llMessageLinked(LINK_SET, 0, "vice ctrl", "");
}
control(key id, integer level, integer edge)
{
if ((edge & CONTROL_ML_LBUTTON) || (edge & CONTROL_LBUTTON))
{
llMessageLinked(LINK_SET, level&(CONTROL_ML_LBUTTON|CONTROL_LBUTTON), "gun ctrl", "");
}
}

}