Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to move in direction prim faces

Ferret Bjornson
Escape! Designer
Join date: 29 Oct 2005
Posts: 97
05-03-2006 20:44
I am trying to figure out how to move a prim in the direction it's facing, say on touch. So a sliding door, if i spin it, will not need me to say "okay instead of moving 2 meters in the X, move -2 meters in the Y" in the script, but all i need is to turn it and it knows to move towards a particular direction. I am trying to get it to move 2 meters in the "local Y" so it always moves towards what it thinks is the Y..... but no matter what I do it always moves in the real Y. this is what I have to start with:

state_entry()
{
rot = llGetRot();
closed = llGetLocalPos();
opened = (closed + door_offset);
}

touch_start(integer parameter)
{
if (open)
{
vector offset = (closed - llGetLocalPos()) / steps;
while ( llVecDist(llGetLocalPos(), closed) > 0.1 )
{
llSetPos(llGetLocalPos() + offset);
}
llSetPos(closed);
open = FALSE;
}
else
{
vector offset = (opened - llGetLocalPos()) / steps;
while ( llVecDist(llGetLocalPos(), opened) > 0.1 )
{
llSetPos(llGetLocalPos() + offset);
}
llSetPos(opened);
open = TRUE;
}
}
_____________________
Adriana Caligari
Registered User
Join date: 21 Apr 2005
Posts: 458
05-03-2006 22:20
I notic you get rotation - but dont use it ?

I am no expert on rotations ( hate them ) but this is the sorta thing you should be doing ( i think )

Old_position = llGetPos()

Offset = <0,2,0>

New_Position = old_position + ( Offset * llGetRot() )


Then when you rotate the object is always moves in the correct direction.

(Read up on the the wiki - there is quite a discussion on there about rotational movement )
Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
05-04-2006 07:33
I modified a sliding door script to deal with directional changes. Here is what I did.

CODE

//global variables
vector vOffset = <0,0,0>;
integer iSteps = 12; //number of steps door moves
integer direction; //keeps track of which direction to move, whether x or y.
.
.
.
//startup code
vector size = llGetScale();
if (size.x > size.y)
{
direction = 0;
vOffset.x = size.x / iSteps;
}
else
{
direction = 1;
vOffset.y = size.y / iSteps;
}

.
.
.
//movement code
vector vOffsetMove = vOffset * direction * llGetRot();
integer i;
vector basepos = llGetPos();
for (i = 0; i < iSteps; i++)
{
llSetPos(basepos + i*vOffsetMove);
}



Let me know if you have questions about this. I have not included the whole code, but just snippets of it . . .

Baron Hauptmann
Ferret Bjornson
Escape! Designer
Join date: 29 Oct 2005
Posts: 97
05-04-2006 10:42
I ended up canning my rotation commands when i had too many doors offworld, so I left that in there alone.

I will try these tonight, ty!
_____________________
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
05-04-2006 17:21
This is easy, use one of the three llRot2____ functions. llRot2Fwd() is along the X-axis, llRot2Left() is the Y-axis, and llRot2Up() is the Z-axis.

If you want the prim to move forward along its local X-axis, you can do llSetPos(llRot2Fwd(llGetRot()) * 1). This will move the prim 1m along the X-axis. Of course, you can multiply by -1 to go backwards along X or 10/-10 to jump by 10m. The limit is somewhere between 10 & 15.