|
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
|
05-26-2008 06:55
i did this one script a wile back and somehow lost the script, what it did was when you collided with a prim it would llApplyImpulse to "kick" it the oppisite way from where it was hit, is there anyone that would know how to make that, i completly forget how i did it
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
05-28-2008 06:39
The biggest choice for this is going to be deciding the amount and direction of the impulse. Do you want to base it on the avatar/object's velocity, or the position of the avatar, or the relative horizontal position of the avatar, or some kind of combination of those, or what? Here I'll assume an impulse in the opposite (horizontal) direction of the colliding avatar/object. However, I'm going to angle it up a bit so the object won't just slide along the ground, and I'll assume a strength proportional to the avatar's velocity relative to the object. (This isn't very physically sound, but remember we're modeling a kick, not a simple collision.) (Note: Not yet compiled; may need minor syntax fixes.) float THETA = 0.25; // About 15 degrees float KICK_IMPULSE_MULTIPLIER = 3.0; // Multiplied by avatar velocity float MIN_KICKER_SPEED = 0.5;
default { collision_start(integer nDetected) { vector pos = llGetPos(); vector vel = llGetVel();
vector kickSum = ZERO_VECTOR; integer i; for (i = 0; i < nDetected; ++i) { vector kickerPos = llDetectedPos(i); vector kickerVel = llDetectedVel(i);
if (llVecMag(kickerVel) >= MIN_KICKER_SPEED) { vector relPos = pos-kickerPos; relPos.z = 0.0; relPos = llVecNorm(relPos);
float strength = llVecMag(kickerVel-vel);
kickSum = strength*relPos; } }
if (kickSum == ZERO_VECTOR) { return; }
vector trajY = <0.0, 0.0, 1.0> % llVecNorm(kickSum); vector dp = KICK_IMPULSE_MULTIPLIER*kickSum*llAxisAngle2Rot(trajY, -THETA);
llApplyImpulse(dp, FALSE); } }
|