Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Two Way Collisions

Landing Normandy
Proposing 4968
Join date: 28 Nov 2005
Posts: 240
04-02-2008 13:19
I'm trying to get a two-way collision detection working. I've created two prims and put essentially the same script in both and it's not working. Basically, what happens is that as you pass through the first object, it sends a link message to the other object in the set (LINK_ALL_OTHERS) with the key of the agent in it. When you then pass through the other object it checks to see if the detected key is the same as the one it last received from the link_message event. If so then it IMs you a message, which is different from if you go the other way.

My script is like this:

CODE
key last_person;

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

collision_start(integer num_detected)
{
last_person = llDetectedKey(0);
llMessageLinked(LINK_ALL_OTHERS, 0, llDetectedName(0), llDetectedKey(0));
}

link_message(integer sender_num, integer num, string str, key id){
if (id == last_person){
llInstantMessage(id, "Hello " + str + ". You are coming in.");
}
}
}


The other part in the link set just has a different llInstantMessage in it.

It will work when I set it to LINK_SET but the message only comes from the parent object so I assume that's where my problem is coming in?

Any help gratefully received!
_____________________
<VOTE PROPOSITION 4968/>
http://jira.secondlife.com/browse/VWR-4968
For SecondLife Builders who need better mapping for better building
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
04-02-2008 14:52
Does the collision_start event really get raised as a collision occurs with each prim in the linkset, or does the event only occur once for the entire linkset? Would also including a collision_end solve the problem?

CODE

key last_person;

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

collision_start(integer num_detected)
{
last_person = "";
llMessageLinked(LINK_ALL_OTHERS, 0, llDetectedName(0), llDetectedKey(0));
}

link_message(integer sender_num, integer num, string str, key id)
{
last_person = id;
}

collision_end(integer num_detected)
{
if (llDetectedKey(0) == last_person) llInstantMessage(id, "Hello " + llDetectedName(0) + ". You are coming in.");
}

}
Landing Normandy
Proposing 4968
Join date: 28 Nov 2005
Posts: 240
04-02-2008 20:47
As far as I can understand from the Wiki then it occurs once for the link set unless you have a collision event in each prim, which I do. It as to know which way around the collisions happen. If it happens in one order then you get a greeting, and if it happens in the other then you are given a farewell message. I shall try your version though and see how it goes, thanks

[edit]Just tried your code, had to change it a little as you'd called id in a different event where it wasn't defined but it still doesn't work properly :([/edit]
_____________________
<VOTE PROPOSITION 4968/>
http://jira.secondlife.com/browse/VWR-4968
For SecondLife Builders who need better mapping for better building
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
04-03-2008 05:07
From my understanding the collision* events occur within all scripts in any prim in a linkset, you cannot isolate a single prim to fire a single event. Unfortunately you can't even use llDetectedLinkNumber with VolumeDetect to figure out which prim was collided with (I know as I spent a few hours last night trying to get this working and llDetectedLinkNumber would return 0 for VolumeDetect collisions, changing to a touch event worked fine, proving the code I was using was not in error). What about two non-phantom prims on the ground, collisions with these on the way in and out would result in a collision event and you can grab the llDetectedLinkNumber to figure which one was hit first and therefore the direction of travel. Alternatively you can grab the velocity of the avatar as they pass through the volumedetect prim and resolve it to find if it's inwards or outwards.
_____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum
Landing Normandy
Proposing 4968
Join date: 28 Nov 2005
Posts: 240
04-03-2008 06:42
Ah, you can get an avatar's velocity eh? I've never seen that done. I'll have to take a look at that as it sounds like it's more what I'm looking for.

I'll take a look in the Wiki to see what I can do with it, many thanks
_____________________
<VOTE PROPOSITION 4968/>
http://jira.secondlife.com/browse/VWR-4968
For SecondLife Builders who need better mapping for better building
Landing Normandy
Proposing 4968
Join date: 28 Nov 2005
Posts: 240
04-03-2008 08:22
Right, I've got it handing out a message depending on which way the agent passes through now, by putting llDetectedVel(0) into a vector and saying if vector.x > 0 then say Welcome and if vector.x < 0 then say good bye.

This works fine for this particular one, but if I want to rotate it then it's not ideal. How would I go about making it so that it would work when rotated?

Thanks for all the help!
_____________________
<VOTE PROPOSITION 4968/>
http://jira.secondlife.com/browse/VWR-4968
For SecondLife Builders who need better mapping for better building
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
04-03-2008 09:28
From: Landing Normandy
This works fine for this particular one, but if I want to rotate it then it's not ideal. How would I go about making it so that it would work when rotated?

Transform the velocity to the object's coordinates:

CODE

vector avatarVel = llDetectedVel(i);
vector relativeAvatarVel = avatarVel/llGetRot();
if (relativeAvatarVel.x > 0.0)
{
...
} else
{
...
}
Landing Normandy
Proposing 4968
Join date: 28 Nov 2005
Posts: 240
04-03-2008 11:12
That seems to work pretty well for me actually, thank you.

In the end I've used this:

CODE

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

collision_end(integer i)
{
vector avatarVel = llDetectedVel(0);
vector relativeAvatarVel = avatarVel/llGetRot();
if (relativeAvatarVel.x > 0.0)
{
llInstantMessage(llDetectedKey(0), "Hello " + llDetectedName(0) + ". Welcome to the store. ");
}
else
{
llInstantMessage(llDetectedKey(0), "Goodbye " + llDetectedName(0) + ". We hope to see you again soon. ");
}

}

}


Thanks a lot
_____________________
<VOTE PROPOSITION 4968/>
http://jira.secondlife.com/browse/VWR-4968
For SecondLife Builders who need better mapping for better building