Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rezzing Object From Attachment 1 meter infront of me?

Nyx Alsop
Registered User
Join date: 14 Dec 2008
Posts: 252
11-25-2009 12:32
I'm trying to rezz an object from an attachment directly infront of me, but using llGetLocalPos, it gives a strange coodinate, it's not the one where I am, it's much smaller?
Monster Behemoth
Registered User
Join date: 22 Dec 2004
Posts: 6
11-25-2009 12:52
When you use llRezObject, you need to use region coordinates so it will rez in the right place. The problem with using llGetLocalPos is that is gives the position with the attachment point as the origin, so it will always be something rather small. You need to call llGetPos(), which will return the region coordinates. Be careful because calling llGetPos() in an attachment will return the position of the avatar, not the actual object.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-25-2009 12:54
it's either the offset from the attach point, or the offset from the root (can't remember it's on the LSL portal if you look)

IIRC llGetRootPosition is what you want, and dont forget to rotate based on the av;s rotation (getting the av's position should work too)
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Jenni Darkwatch
Registered User
Join date: 21 Jun 2009
Posts: 25
11-25-2009 12:55
From: Nyx Alsop
I'm trying to rezz an object from an attachment directly infront of me, but using llGetLocalPos, it gives a strange coodinate, it's not the one where I am, it's much smaller?


As the wiki says: llGetLocalPos gives the position of the attached prim relative to the root (the avatar).

What you're looking for is llGetRootPosition.
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
11-25-2009 15:51
When I'm trying to rez stuff in front of me from an attachment, I find
CODE
llGetPos()+ < 1.0,0.0,0.0 > *llGetRot()
works fine, assuming it's the attachment's root prim from which I'm rezzing.

According to the wiki, llGetPos() "When called from the root of an attachment, returns the wearer's position. When called in any child prim, always returns that prim's region position" and llGetRot(), when called from the attachment's root, returns the "global rotation of avatar."

Or are you trying to rez it in front of the attachment point itself rather than the avatar?
Nyx Alsop
Registered User
Join date: 14 Dec 2008
Posts: 252
11-25-2009 16:39
I'm trying to rezz, infront of the avatar, regardless of where there looking.
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
11-25-2009 17:09
The code I posted, then, should do it.
CODE
 llRezAtRoot("object", llGetPos()+ < 1.0,0.0,0.0 > *llGetRot(), ZERO_VECTOR, llGetRot(), 0); 
should make the object rez one meter in front of the avatar, if called from the root prim of an attachment the avatar's wearing, no matter where on the avatar the rezzing prim is attached. With the caveat, as I recall, that the avatar isn't in mouselook at the time (in which case it's 1 meter in the direction the avatar's looking -- that's how guns know where to shoot).
Nyx Alsop
Registered User
Join date: 14 Dec 2008
Posts: 252
11-25-2009 17:21
Is there a way to get whitch direction the Av is looking in?
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
11-25-2009 17:28
I use:
llRot2Fwd(llGetRot()) for the direction vector. That automatically rezzes 1.0m in front. You can use llRot2Left() or llRot2Up() for positions along the Y or Z axis. If you want to rez 1m behind, multiply by -1.0. If you want to rez 5m, multiply by 5.0.
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-25-2009 17:58
From: Nyx Alsop
Is there a way to get whitch direction the Av is looking in?

Take a look at this thread from a couple of days ago...
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
11-25-2009 22:33
I don't think that's what Nyx is asking, guys. DoteDote's code (which does the same as mine only expressed differently) will rez the object relative to the way the avatar is facing.

I mentioned that it works differently if you're in mouselook, because then -- as I understand it -- llGetRot() doesn't return where you're facing but where you're looking, which is why if you're firing a gun, you can aim by moving your mouse around rather than swiveling your whole avatar round.

If I've properly understood it, Nyx is now asking how you'd rez something in the direction your camera's pointing, as opposed to in front of you, if you're not in mouselook.

This seems do that -- rez an object from an attachment 1 meter from the avatar in the direction at which the camera is pointed:
CODE
string my_object;

default
{
state_entry()
{
my_object = llGetInventoryName(INVENTORY_OBJECT,0);
if(llGetAttached()!=0){
llRequestPermissions(llGetOwner(),PERMISSION_TRACK_CAMERA);
}
}

touch_start(integer total_number)
{

vector CameraPoint=llGetCameraPos()+1.0*llRot2Fwd(llGetCameraRot()); // 1 meter in front of my camera, wherever that is
vector myPos=llGetPos();
rotation rot = llRotBetween( < 1.0, 0.0, 0.0 >, llVecNorm( CameraPoint-myPos ));// angle between the two
vector targetPos = llGetPos()+< 1.0,0.0,0.0 > *rot; //one meter from me at that angle.
if(llGetPermissions()&PERMISSION_TRACK_CAMERA){
llRezAtRoot(my_object, targetPos,ZERO_VECTOR,llGetRot(),0);
}
}

attach(key id){
llResetScript();
}


}
Nyx Alsop
Registered User
Join date: 14 Dec 2008
Posts: 252
11-26-2009 03:13
Innula Zenovka

Thanks very much for the code.

llGetPos()+ < 1.0,0.0,0.0 > *llGetRot()

works perfect, but why does it work? when incrementing X by one, surely X wont always be foward in llGetPos?

(trying to understand, thanks)
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
11-26-2009 07:11
From: Nyx Alsop
Innula Zenovka

Thanks very much for the code.

llGetPos()+ < 1.0,0.0,0.0 > *llGetRot()

works perfect, but why does it work? when incrementing X by one, surely X wont always be foward in llGetPos?

(trying to understand, thanks)

That's the way vector algebra works. The product < A > * < B > describes the angular displacement between them; that is, how much you have to turn to get from wherever B points to wherever A points. In this case, since A only has a non-zero component in the forward direction, what you're asking is "How much do I have to turn from llGetRot() to 'forward'?" The magnitude of the resultant vector is the displacement in that final direction. So, writing

llGetPos() + <1.0,0.0,0.0> * llGetRot()

means "Get my current position, turn me from llGetRot() to 'forward' and apply an offset of 1m in the resultant direction."
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask.... ;)

Look for my work in XStreetSL at
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
11-26-2009 08:01
What Rollig said...

I find the easiest way to think about this is just to remember that multiplying by llGetRot() is, in effect, telling the script to use the local ruler mode in edit. The wiki article, http://wiki.secondlife.com/wiki/Rotation is very clear and accessible for non-mathematicians like me, and I find Void Singer's cheat sheet at http://wiki.secondlife.com/wiki/User:Void_Singer/Rotations absolutely invaluable.

ETA You might also find this thread answers a lot of questions about rotations: /54/31/313876/1.html