Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Detect face collision

Redlag Mayo
Registered User
Join date: 27 May 2008
Posts: 8
01-07-2010 04:37
Hi,

I am a beginner scripter and i am trying to solve one problem.
My idea is that the "phantom prim" only shout when an object (other prim) collisions with one of the 6 faces of the prim(one in particular), entering by one side and crossing this face, and not backwards (crossing other face of the prim and going out by the right face of the prim).
So i want that the phantom prim shout onlye when another object crosses it by one direction.
I think that if i can force that the phantom prim shout when another object start the collision crossing one face and end the collision crossing the oposite face, i will have it.

Is it possible?

Thank you and Happy New Year.
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
01-07-2010 07:03
If you don't mind wasting an extra prim, why not make your detector out of two prims sandwiched together? If the colliding object hits prim A before prim B, you know it was going one direction; if it hits B before A, you know it was going in the opposite direction. That kind of detector would be easy to construct, although you'd have to do some experimentation to see how badly lag might mess it up. Worth a try anyway.
_____________________
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
Jack Abraham
Lantern By Day
Join date: 11 Apr 2008
Posts: 113
01-07-2010 09:16
I don't know that it's possible as you outline it, Redlag, but I do something similar by getting the collider's velocity and using that to determine which way he's going.
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
01-07-2010 09:34
ETA edited for important clarification
This is how i would detect someone walking into face 2 (and only face 2) of a flattened cube like a door:
CODE
default
{
state_entry()
{

llVolumeDetect(TRUE);

}

collision_start(integer num_detected)
{

integer i;
key collider = llDetectedKey(i);
vector pos = (llDetectedPos(i) - llGetPos()) / llGetRot();
if ( pos.x > 0){ // play with this line to use different faces
llSay(0,"ouch");
}
}
}
As is, it would also detect collisions on the half of each face that has a positive x coordinate.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-07-2010 12:02
if the object is not moving quickly you can use volume detect and get the objects position as reported in the collision, apply the rot of the prim and you can tell which face it's striking simply by the the signs of the returned vector.

CODE

//-- default cube shape
string uGetDirection( float vFltVal ){
integer vIdxVal = (integer)(vFltVal > 0.0);
return llGetSubString( "+-", vIdxVal, vIdxVal );
}

default{
state_entry(){
llVolumeDetect( TRUE );
}

collision_start( integer vIntCollides ){
string vStrRpt = "impact on ";
vector vIntTst = (llGetPos - llDetectedPos( 0 )) * llGetRot();
if (llAbs( vIntTst.x ) > llAbs( vIntTst.y )){
if (llAbs( vIntTst.x ) > llAbs( vIntTst.z )){
vStrRpt += uGetDirection( vIntTst.x ) + "X";
}else{
vStrRpt += uGetDirection( vIntTst.z ) + "Z";
}
}else if (llAbs( vIntTst.y ) > llAbs( vIntTst.z )){
vStrRpt += uGetDirection( vIntTst.y ) + "Y";
}else{
vStrRpt += uGetDirection( vIntTst.z ) + "Z";
}
llOwnerSay( vStrRpt + " face" );
}
}

written on the fly, may contain errors

ETA:
the bigger the internal volume and the slower the collider the better, bullets tend to get the position reorted a bit slo and may have moved far enough that they report the wrong face...
_____________________
|
| . "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...
| -
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
01-07-2010 13:27
From: Jack Abraham
I don't know that it's possible as you outline it, Redlag, ......

LOL .... My name invites creative misspelling, but that's a lovely one. Thank you, Jack. You made my day. :D
_____________________
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
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-07-2010 13:51
From: Rolig Loon
LOL .... My name invites creative misspelling, but that's a lovely one. Thank you, Jack. You made my day. :D

then I hope looking at the OP's name doesn't unmake your day =)

here's the above outlined as OP described, using the x axis faces of a cube.

CODE

key gKeyCld;
vector gSizObj;

default{
state_entry(){
gSizObj = llGetScale() / 2.0;
}

collision_start( integer vIntCld ){
if (gKeyCld == "";)
vector vPosCld = (llGetPos() - llDetectedPos( 0 )) * llGetRot();
//-- these 3 lines allow for non cubic shape
vPosCld.x /= gSizObj.x;
vPosCld.y /= gSizObj.y;
vPosCld.z /= gSizObj.z;
if (vPosCld.x > vPosCldy.y && vPosCld.x > vPosCld.z && vPosCld.x > 0.0){
gKeyCld = llDetectedKey( 0 );
}
}
}

collision_end( integer vIntCld ){
if (llDetectedKey( 0 ) == gKeyCld){
vector vPosCld = (llGetPos() - llDetectedPos( 0 )) * llGetRot();
vPosCld.x /= gSizObj.x;
vPosCld.y /= gSizObj.y;
vPosCld.z /= gSizObj.z;
if (vPosCld.x < vPosCldy.y && vPosCld.x < vPosCld.z && vPosCld.x < 0.0){
llOwnerSay( "Achievement!" );
gKeyCld = "";
}
}
}
}
_____________________
|
| . "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...
| -
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
01-07-2010 14:08
CODE
vector gvFacing = <1.0,0.0,0.0>; // Set this to the direction to detect

default {
state_entry() {
llVolumeDetect(TRUE);
}
collision_start(integer piDetectedCount) {
vector lvVelocity;
float lfAngle;

lvVelocity = llDetectedVel(0);

// Compute the angle between two vectors
lfAngle = llFabs(llAcos(llVecNorm(gvFacing) * llVecNorm(lvVelocity)));

llOwnerSay((string)(lfAngle * RAD_TO_DEG));
if (lfAngle < PI_BY_TWO)
llOwnerSay(llDetectedName(0)+" passed through!");
}
}


Set the gvFacing variable to the direction you want to detect (<1.0,0.0,0.0> is East through the prim) . You can also use the prim's facing/rotation instead of hard-coding it, but it will depend on which exact face you want (use llRot2Fwd(llGetRot()) for positive-X, for example).
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
01-07-2010 14:50
From: Void Singer
then I hope looking at the OP's name doesn't unmake your day =)
Oh, dang ...... There goes the day.
/me goes back to her corner, sheepishly :o
_____________________
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
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-07-2010 15:16
From: Rolig Loon
Oh, dang ...... There goes the day.
/me goes back to her corner, sheepishly :o

aww we still love ya rollegg =)
_____________________
|
| . "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...
| -
Redlag Mayo
Registered User
Join date: 27 May 2008
Posts: 8
01-08-2010 03:53
Hi again,

thank you all for your advices, especially to Talarus Luan, which code helped me. :)