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 ^^