Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Vector Help: Coming or Going?

Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
07-31-2007 16:48
I want to have a couple of sensor arrangements: one a hollow cube, and the other a flat panel. It's set to llVolumeDetect(TRUE), and I have the collision event set up. I only want it to trigger in one direction, though, and that's where I'm running into difficulty. In the case of the cube, I want it to trigger if the person is approaching the center; in the case of the panel, I want it to trigger only on one side, regardless of orientation. I've read the docs on the vector functions and operators, and tried a few things, but I'm not getting it. Could some wise soul set my feet upon the right path?
Qie Niangao
Coin-operated
Join date: 24 May 2006
Posts: 7,138
07-31-2007 20:43
llDetectedVel() might give the script a pretty good chance of guessing whether the collider is coming from the desired direction.
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
07-31-2007 21:04
You can use something *like* the following:
From: someone
integer isApproaching = llDetectedVel(0) * (llGetPos() - llDetectedPos(0)) > 0;


I say *like* because it is untested and probably wrong, but the idea is to calculate the dot product of the object's velocity vector with the direction vector to the object, and return TRUE if that value is greater than zero.

I'm very tired, and I probably got it a bit wrong, but hopefully that will prompt someone to test it and provide the correct code?


.
_____________________
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
07-31-2007 21:29
Here are a couple of useful functions for determining whether a detected object or avatar is in front of or is facing the sensing object.

From: someone
integer isTargetInFront( rotation myDir, vector myPos, vector targetPos )
{
return ( llRot2Fwd( myDir ) * ( targetPos - myPos ) ) > 0;
}

integer isTargetFacingMe( vector myPos, vector targetPos, rotation targetDir )
{
return ( llRot2Fwd( targetDir ) * (mypos - targetPos) ) > 0;
}


Don't know if either of these will be helpful for you, but I'm posting them on the off chance.

.
_____________________
Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
08-01-2007 04:43
From: RobbyRacoon Olmstead
You can use something *like* the following:

integer isApproaching = llDetectedVel(0) * (llGetPos() - llDetectedPos(0)) > 0;

I get a type mismatch with this. I have no clue why; it makes no sense. I even tried breaking it down:

vecMyPosition = llGetPos();
vecVelocity = llDetectedVel(0);
vecPosition = llDetectedPos(0);
vecDiff = vecMyPosition - vecPosition;
intIsApproaching = vecVelocity * vecDiff;

It gives the error on the last line.
Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
08-01-2007 06:00
From: RobbyRacoon Olmstead
Here are a couple of useful functions for determining whether a detected object or avatar is in front of or is facing the sensing object..


OK, the Facing function gave me a solution for the cube sensor. I had to modify it, as the avatar's direction of movement is what I'm looking for, so it becomes:

(vecAvVelocity * (vecMyPosition - vecAvPosition)) > 0;

Which kind of actually makes sense to me, sort of, so maybe I'm starting to get some idea of how this spatial stuff works! (And which, now that I look at it, is what you first suggested; I simply omitted the boolean operation there. I still don't understand why I got a type mismatch, though, since the dot product of two vectors is an integer, isn't it?)

Now to work out the flat sensor, which I think I can get.
RobbyRacoon Olmstead
Red warrior is hungry!
Join date: 20 Sep 2006
Posts: 1,821
08-01-2007 07:26
From: Siann Beck
OK, the Facing function gave me a solution for the cube sensor. I had to modify it, as the avatar's direction of movement is what I'm looking for, so it becomes:

(vecAvVelocity * (vecMyPosition - vecAvPosition)) > 0;

Which kind of actually makes sense to me, sort of, so maybe I'm starting to get some idea of how this spatial stuff works! (And which, now that I look at it, is what you first suggested; I simply omitted the boolean operation there. I still don't understand why I got a type mismatch, though, since the dot product of two vectors is an integer, isn't it?)

Now to work out the flat sensor, which I think I can get.


Technically the dot product of two vectors is a float, actually. I was using an integer variable because of the " > 0" part making that expression into a boolean.

I would have made that last line into:
CODE
         intIsApproaching = (vecVelocity * vecDiff) > 0;


Sounds like you got it working, though, yay!!! :D



.
_____________________
Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
08-01-2007 17:31
From: RobbyRacoon Olmstead
Technically the dot product of two vectors is a float, actually.
Doh! I knew that. OK, I know my forehead-bashing board is around here somewhere....

OK, for the flat panel, I *think* I understand conceptually what I want to do, but implementing it hasn't gone well.

If I have a phantom prim with zero rotation, and walk through it along the Y axis, I can get the velocity and check delta-Y to see if it's positive or negative, thus indicating which side the collision occurred on. And if the prim were never rotated, that would be fine. But if it is, it seems to me I should be able to convert the rotation to a Euler and subtract it from the velocity, and that should give me velocity relative to a zero rotation. But it doesn't.

Any suggestions?
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
08-01-2007 17:49
Maybe try using llRot2Left(llGetRot()) to get the vector for the local Y axis. I don't know if it'll work if you directly convert it to a euler, because a rotaion expressed as a euler is... the rotation around all 3 axes? *brain explodes* :) Anyway, I usually use llRot2xxx to find out which way a prim is facing. That works for me, and I haven't tried to figure out the math beyond that :)
DangerDave Writer
Registered User
Join date: 3 Mar 2007
Posts: 3
Rotation and Eulers and Prims..Oh My!
08-03-2007 05:25
I've played around with rotations a bit with my dart launcher and "Auto Targeting Box of Doom" and, for something useful, a single-prim object that can be used as Horizontal Blinds, sliding door, skylight, etc. - the blinds "shrink up" to the Top Center of the object, regardless of how it is rotated, so it can be used as a sliding door on a hole on the side of a slanted hill, even.
Day Oh
Registered User
Join date: 3 Feb 2007
Posts: 1,257
08-03-2007 05:39
Divide the velocity vector by the object's rotation... that will basically rotate the velocity vector so that it's on the object's local axes. If the velocity vector went straight forward along the object's X axis, you'll have a vector that says, forward along the X axis.
Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
08-04-2007 06:27
Division.

I knew I was on the right track, just the wrong math. Remove the rotation from the equation, so that velocity is relative to a zero rot.

Excellent! Thank you! And thanks to everyone who provided input.

Daylight come and me wan' go home.