Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

object speed detection (for collision)

Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
03-10-2008 15:22
ive been making a car latly for rping in city envirements and the way im working on making the car depending on your speed when you hit into any solid object (other than avatars/land) it will couse a message to be sent to the rest of the car trigering the actian of parts

the problem right now i cant seam to fix is you can tap into something and it will couse the action to hapen but when i flip the (< >;) around it wont trigger it will littaly eather trigger at very little touch or wont trigger at all

CODE

key sound = "";
integer crash;
default
{
state_entry()
{
//llCollisionFilter("wall", NULL_KEY, TRUE);
llMessageLinked(LINK_SET, 0, "repair", NULL_KEY);
llListen(0,"",llGetOwner(),"");
}
listen( integer channel, string name, key id, string message )
{
if(message == ".crashstart")
{
llMessageLinked(LINK_SET, 0, "crash", NULL_KEY);
}
if(message == ".crashrepair")
{
llMessageLinked(LINK_SET, 0, "repair", NULL_KEY);
}
}
//collision_end(integer x)
collision(integer x)
{
if(llDetectedType(0) & AGENT)
{
}
else if(crash == FALSE)
{
if(llVecDist(llGetPos(),llDetectedPos(0)) > 5)
{
llTriggerSound(sound,1);
llMessageLinked(LINK_SET, 0, "crash", NULL_KEY);
crash = TRUE;
}
}
if(crash == TRUE)
{
llSetStatus(STATUS_PHYSICS,FALSE);
}
}
land_collision(vector y)
{
}
}
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
03-10-2008 15:30
You can try:

CODE

vector velocity = llGetVel();
float speed = llVecMag(velocity);

vector otherObjectVelocity = llDetectedVel(n);
float otherObjectSpeed = llVecMag(otherObjectVelocity);


But I'm not sure how much the velocity will have already been affected by the physical collision at the time that the 'collision_start' event is triggered. You may instead/also need a frequent timer to remember velocity so you can use the last recorded one to deal with the results of the collision.
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
03-10-2008 17:50
im gong alittle stupid right now but how would i incorperate that into my script for i need to create a list to rember the last valocitys?
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
03-10-2008 18:23
Do you need a history of velocities, or just the most recent?

CODE

float TIMER_PERIOD = 0.1;

velocity lastVelocity = ZERO_VECTOR;

default
{
state_entry()
{
llSetTimerEvent(TIMER_PERIOD);
}

timer()
{
lastVelocity = llGetVel();
}

collision_start(integer nDetected)
{
float speed = llVecMag(lastVelocity);
// ...
}
}
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
03-11-2008 14:25
dosent seam to work but compiles and lsleditor dosent trow out any errors eather here is what i got

CODE

key sound = "";
float TIMER_PERIOD = 1;
vector lastVelocity;
integer crash;

default
{
state_entry()
{
llSetTimerEvent(TIMER_PERIOD);
crash = FALSE;
}

timer()
{
lastVelocity = llGetVel();
}

collision_start(integer nDetected)
{
float speed = llVecMag(lastVelocity);
{
if(llDetectedType(0) & AGENT)
{
}
else if(crash = FALSE)
{
if(speed < 1)
{
llTriggerSound(sound,1);
llMessageLinked(LINK_SET, 0, "crash", NULL_KEY);
crash = TRUE;
}
}
if(crash == TRUE)
{
llSetStatus(STATUS_PHYSICS,FALSE);
}
}
}
land_collision(vector y)
{
}
}