Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

on collision help.

Benson Bellios
Registered User
Join date: 15 Dec 2007
Posts: 3
01-21-2008 03:49
Hi all i hope someone can help me with this. I am relativly new to scripting i was wondering if there was anyway to tell which face of a prim you have walked into.
What i am trying to do is make a swinging door that goes one way when you walk into one side, and the other when walked into the other. I hope this makes sense. :)
Siann Beck
Beauty & Braiiiiinsss!
Join date: 14 Jul 2007
Posts: 140
01-21-2008 05:18
While you can't detect the side the collision occurred on, you can detect the avatar position and direction of movement, with llDetectedPos() and llDetectedVel(). You can then use this to determine which side they collided with.
Benson Bellios
Registered User
Join date: 15 Dec 2007
Posts: 3
01-21-2008 06:02
so would i use llgetpos() to get the position of the prim then compare it to what lldetected position()? Do you have a small snippet as an example as i havent gotten that far in depth yet :(
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
01-21-2008 06:39
Look at llVolumeDetect

You could use a phantom prim on one side of the door. They will wither collide with the door on the one side and it will swing away or they will collide with the phnatom prim on the other and swing opposite way.

EDIT: WOW! Excuse the typos. That's what I get for trying to sneak in a quick reply during work hours:)
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
Benson Bellios
Registered User
Join date: 15 Dec 2007
Posts: 3
01-21-2008 08:18
that sounds easier thanks i will give it ago :)
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-21-2008 09:19
come to that if you're using 2 prims you don't need llVolumeDetect.

I've seen the getPos/detectedPos used in touch doors to good effect

the single prim door can be linked to the larger structure, but the math is simpler for the 2 prim unlinked door, depends on your needs

the former needs only detect which prim is touched/collided

the latter IIRC uses a combination of rotated offset and llVecDist something like
CODE

vector vPosAv = llDetectedPos( 0 );
vector vPosDoor = llGetPos();
if (llVecdist( vPosAv, vPosDoor ) > llVecdist( vPosAv, vPosDoor + <.01, 0, 0> * llGetRot() )){
//-- swing this way
}else{
//-- swing that way
}
_____________________
|
| . "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...
| -
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
01-21-2008 11:06
Or, more simply (if the x-axis points toward the "outside";) I think you could use:

CODE

vector avatarRelPos = (llDetectedPos(0)-llGetPos())/llGetRot();
if (avatarRelPos.x > 0.0)
{
// Handle collision from outside of door
} else
{
// Handle collision from inside of door
}
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-21-2008 12:44
seems to work for me, I could even generalize it out to my door script like so.

CODE

//--// v7-D Feebie Type 1 Door Script //--//
//--// Works At ANY Angle //--//

//-- works in ANY single prim door, linked or un-linked
//-- works in muti prim doors NOT linked to a larger structure
//-- REQUIREMENTS: a cut root prim, suggest cube, pathcut start=.125, end=.625
//-- CAVEAT: single prim doors are limited to 5m width

//--// USERS MODIFY HERE v
integer gIntDoorSwing = 90;
//-- use -# to reverse the direction of swing, eg. -90;

integer gBooOpen;
rotation gRotDoorSwing;

fSwing(){
if (gBooOpen){
gRotDoorSwing.s *= -1;
}else{
gRotDoorSwing = llEuler2Rot( <.0, .0, (float)gIntDoorSwing * DEG_TO_RAD> );
vector gPosTest = (llDetectedPos(0)-llGetPos())/llGetRot();
if (gPosTest.y > 0.0){
gRotDoorSwing.s *= -1;
}
}
gBooOpen = !gBooOpen;
llSetLocalRot( gRotDoorSwing * llGetLocalRot() );
}

default{
touch_start( integer vIntTouches ){
fSwing();
}

collision_start( integer vIntCollides ){
fSwing();
}
}

//-- IF Redistributing as-is:
//-- Please leave script full permissions & include all comments


works for touches and collides
_____________________
|
| . "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...
| -
Ephraim Kappler
Reprobate
Join date: 9 Jul 2007
Posts: 1,946
Where's the swing?
11-07-2008 07:40
What goes out must come in again and I was wondering if it were possible to modify Void's elegant script to swing the door closed without the need to touch it or collide with it.

I'm thinking George Clooney racing some poor bleeding soul on a gurney through the corridors of County General Hospital or that desperate dash I sometimes make for the toilet as the nausea of an atrocious hangover reaches its apogee.

To this end I grafted a timer event into the script. It works but, being an utter scripting fool, I thought I might post this for folk with brains to check for a potentially cleaner solution (You there Void? Jesse? Hewee?).

NB: I removed Void's original comments for the purposes of posting.

CODE

float TimeInterval = 1.0; // Added time interval
integer pitch = 5; // Not sure about this but the Close function requires it

integer gIntDoorSwing = 80; // Nice to have the door open a little short of 90 degrees
integer gBooOpen;
rotation gRotDoorSwing;

fSwing(){
if (gBooOpen){
gRotDoorSwing.s *= -1;
}
else
{
gRotDoorSwing = llEuler2Rot( <.0, .0, (float)gIntDoorSwing * DEG_TO_RAD> );
vector gPosTest = (llDetectedPos(0)-llGetPos())/llGetRot();
if (gPosTest.y > 0.0){
gRotDoorSwing.s *= -1;
}
}
gBooOpen = !gBooOpen;
llSetLocalRot( gRotDoorSwing * llGetLocalRot() );
llSetTimerEvent(TimeInterval);
}

Close() // Added to incorporate the timer event
{
llSetTimerEvent(0);
integer i;
for(i = pitch - 1; i >= 0 ; i--)
{
llSetLocalRot( gRotDoorSwing / llGetLocalRot() ); // Seems to do the trick
}
}

default
{
touch_start( integer vIntTouches ){
fSwing();
}
collision_start( integer vIntCollides ){
fSwing();
}
timer()
{
Close();
}
}


Also I noticed that if the timer interval is longer - say two or three seconds - the door bangs back and forth quite convincingly, the way swinging doors do when they are abused by the sudden and impatient passage of a human body or other missile.

This is due to my potential misuse of Void's code in the Close() function. The trouble is that the door only swings back to its original position, which, of course, is what is ultimately required of the script. It would be good, however, if the door could swing back and forth in a wider arc for a bit before eventually closing.

I'm thinking about Anthony Edwards getting it in the face as he hurries after George with the CPR, the stroboscopic image of my back as I collapse over the toilet in violent paroxysms of liquid laughter.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-07-2008 09:39
updated to include a timeout variable, a timer function, and a timer set in the swing function
CODE

//--// v7-D Feebie Type 1 Door Script //--//
//--// Works At ANY Angle //--//

//-- works in ANY single prim door, linked or un-linked
//-- works in muti prim doors NOT linked to a larger structure
//-- REQUIREMENTS: a cut root prim, suggest cube, pathcut start=.125, end=.625
//-- CAVEAT: single prim doors are limited to 5m width

//--// USERS MODIFY HERE v
float gFltTimeout = 3.0; //-- second to wait before auto-close, 0.0 to disable
integer gIntDoorSwing = 90;
//-- use -# to reverse the direction of swing, eg. -90;

integer gBooOpen;
rotation gRotDoorSwing;

fSwing(){
if (gBooOpen){
gRotDoorSwing.s *= -1;
}else{
gRotDoorSwing = llEuler2Rot( <.0, .0, (float)gIntDoorSwing * DEG_TO_RAD> );
vector gPosTest = (llDetectedPos(0)-llGetPos())/llGetRot();
if (gPosTest.y > 0.0){
gRotDoorSwing.s *= -1;
}
}
llSetTimerEvent( (gBooOpen = !gBooOpen) * gFltTimeout);
llSetLocalRot( gRotDoorSwing * llGetLocalRot() );
}

default{
touch_start( integer vIntTouches ){
fSwing();
}

collision_start( integer vIntCollides ){
fSwing();
}

timer(){
fSwing();
}
}

//-- IF Redistributing as-is:
//-- Please leave script full permissions & include all comments


EDIT: removed redundant test from timer, since the timer should turn itself off in the function, this model should also turn the timer off if someone manually closes the door

EDIT part duex: added missing bracket because some cheeky monkey pointed it out... j/k thanks for the catch =)
_____________________
|
| . "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...
| -
Ephraim Kappler
Reprobate
Join date: 9 Jul 2007
Posts: 1,946
11-07-2008 10:39
Thanks for that, Void. It works beautifully.