Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Finding the point on a plane where a velocity crosses.

Ephyu Reino
Registered User
Join date: 18 Jan 2007
Posts: 16
02-19-2008 04:11
I'm using collision detect to note when an object is passing through a wide, flat prim (<0.5,5.0,5.0>;) and trying to rez an object at the point where the prim passes through.. however, using llDetectedPos picks out the center of the prim upon collision, which is very far off if the projectile is long and impacts at an angle.

Someone suggested using llDetectedVel and finding the point at which the vector would cross the plane, but I have no idea where to begin.

The current code, using llDetectedPos is as such:

From: someone

vector pos;
vector sc = llGetScale();
pos = llDetectedPos(0)-llGetPos();
pos = pos / llGetRot();
if(pos.x>0 && llFabs(pos.z) < sc.z / 2.0 && llFabs(pos.y) < sc.y / 2.0){
pos.x = (sc.x)*.6;
pos = pos * llGetRot();
pos = pos + llGetPos();
}
Sho Iuga
Registered User
Join date: 6 Jun 2007
Posts: 35
02-19-2008 05:05
the following should do the trick. At least I hope so:

CODE

rotation planerot = llGetRot();
vector scale = llGetScale();
float thickness = scale.x;
vector vel = llDetectedVel(0);
vector pos = llDetectedPos(0);
vector vel_loc = vel/planerot;
vector pos_loc = pos/planerot;

float hop = pos_loc.x - thickness/2;
//height of projectil center over our plane

float time = hop/vel_loc.x;
//time till projectil center reaches plane

vector imp_loc = pos_loc + vel_loc * time;
//impact point in local coordinates relative to plane center
vector imp = (imp_loc * planerot) + llgetpos();
// in global coords


integer safetycheck()
//make sure projectile didnt go through a different side of the plane
{
if( hop > 0 && imp_loc.y < scale.y/2.0 && imp_loc.z < scale.z/2.0 ) return TRUE;
else return FALSE;
}
Ephyu Reino
Registered User
Join date: 18 Jan 2007
Posts: 16
02-19-2008 08:39
Didn't exactly work. No idea what the error is yet.