Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Predicting Collisions..?

Kisune Perth
Registered User
Join date: 3 May 2005
Posts: 3
05-18-2005 10:15
I'm trying to make a flashy shielder. I know there are anti-push scripts out there, but making a shielder sounds fun ^^


However, I am having trouble coming up with an algorithm to predict collisions on a llSensorRepeat()..

The only one I've come up with is as follows:
CODE

vector velocity;
integer i;
integer k;
integer y;
float tesme;
integer test;
vector testpos;
vector testpos2;
vector newpos;
//
default
{
state_entry()
{
llListen(0,"",llGetOwner(),""); //If I say "shield" it rezzes the shield object
llSensorRepeat("","",AGENT | ACTIVE,90,2*PI,.1);
}
on_rez(integer bla)
{
llListen(0,"",llGetOwner(),"");
llSensorRepeat("","",AGENT | ACTIVE,90,2*PI,.1);
}
sensor(integer t)
{
for(i = 0; i < t; i++)
{
velocity = llDetectedVel(i);
tesme = llVecMag(llGetPos());
if(llVecMag(velocity) > 4)
{
//llSay(0,"Ahh!!"); - If it's not rezzing shields, i use this to see if its even working..
testpos = llDetectedPos(i);
testpos2 = llGetPos();
newpos.x = testpos2.x - testpos.x; //Find the distance between the shielder and the moving object
newpos.y = testpos2.y - testpos.y;
newpos.z = testpos2.z - testpos.z;
if(velocity.x / newpos.x - llRound(velocity.x / newpos.x) < .3)
{
if(velocity.y / newpos.y - llRound(velocity.y / newpos.y) < .3)
{
if(velocity.z / newpos.z - llRound(velocity.z / newpos.z) < .3) //If all the distances in x, y, z are divisable by the Velocity, then it must be 'on line'... (supposadely)
{
//llPushObject(llDetectedKey(i),-velocity * 5, ZERO_VECTOR, FALSE);
if(llVecMag(llDetectedPos(i)) > llVecMag(llGetPos())) { //a crappy way of seeing if its going the right direction
newpos = llGetPos() + ((llDetectedPos(i) - llGetPos()) / 5);
}
else
{
newpos = llDetectedPos(i) + ((llGetPos() - llDetectedPos(i)) / 5);
}


llRezObject("Shield", newpos, ZERO_VECTOR, ZERO_ROTATION, 42);
}
}
}
}
}
}

touch_start(integer total_number)
{
//
llSay(0, "Touched.");
}
listen(integer chan, string name, key id, string m)
{
if(m == "shield") {
llRezObject("Shield", llGetPos() + <0,2,0>, ZERO_VECTOR, ZERO_ROTATION, 42);
}
}
}


I'm no math genius.. This method works, kind of.. but its way too slow. The object always hits the shielder before it generates a shield.

Any suggestions well appreciated ^^
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
05-22-2005 15:52
Doing my unanswered post forum rounds for the day. Here's my reaction.

Your bottleneck appears to be the sensor event code. Instead of using all of that, try something like this.
CODE
sensor(integer t)
{
for(i = 0; i < t; i++)
{
velocity = llDetectedVel(i);
if(llVecMag(velocity) > 4)
llRezObject("Shield", llGetPos() + (3 * llVecNorm(llDetectedPos(i) - llGetPos())), ZERO_VECTOR, ZERO_ROTATION, 42);
}
}

Much simpler.
_____________________
---
lmho Impfondo
Registered User
Join date: 7 Apr 2005
Posts: 31
05-22-2005 19:39
the problem with your suggestion Jeffery is that vecmag doesnt determine wether or not an object is coming toward you or going away from you. It triggers shield rez wether or not an object is coming or going. I have yet to work this kink out.
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
05-22-2005 20:12
True, but the problem here was speed, not necessarily accuracy. Lower the sensor range and it should be of no consequence.

Of course, if you want to really nail it, you can always "fake" it:

CODE
llVecNorm(llDetectedPos(i) - llGetPos()) - llVecNorm(llDetectedVel(i))


Then run the whole vector or select components against a certain threshhold value (say, less than 0.5) - but again, you lose a little speed. Still faster than the above, though. :)
_____________________
---
lmho Impfondo
Registered User
Join date: 7 Apr 2005
Posts: 31
05-22-2005 21:41
thank you for this

you know, its still slower than the sion shield. fancy that!