Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Force Scripting

KINGR Redgrave
Registered User
Join date: 23 Dec 2006
Posts: 37
12-28-2006 21:05
i have this script that forces an object to go up to a set amount of hight and speed and so. what it does s gets the objects mass and multiplies it to get the force amount.

CODE

float objMass = llGetMass();
float Z_force = 10.2 * objMass;



now,if i wanted to force myself or an avatar around me, would i have to put in a llDetectKey command or how would i do that, here is the original script.
CODE


list MENU_BUTTONS = ["Scan", "force"];
list MENU_OPTION = ["help"];
integer MENU_CHANNEL = 1024;


vector startPos;
vector curPos;
vector curForce;
integer second;

default
{
state_entry()
{
llListen(0,"",NULL_KEY,"");
llListen(1024, "",NULL_KEY,"");

llSay( 0, "Hello, Avatar! Touch to launch me straight up.");
llSetStatus( 1, TRUE );
startPos = < 0, 0, 0 >;
}

listen(integer channel, string name, key id, string message)
{
if (llToLower(message) == "help")

llDialog(id," ", MENU_BUTTONS, MENU_CHANNEL);
else if (message == "force")


{



startPos = llGetPos();
curPos = startPos;
curForce = < 0, 0, 0 >;
second = 0;

llSetColor( < 1.0, 0.0, 0.0 > , ALL_SIDES ); // set color to red.

float objMass = llGetMass();
float Z_force = 30.2 * objMass;

llSetForce( < 0.0, 0.0, Z_force >, FALSE );

llSay( 0, "Force of " + (string)Z_force + " being applied." );
llSetTimerEvent(1);
}

}timer()
{
second++;
curPos = llGetPos();
float curDisplacement = llVecMag( curPos - startPos );

if( ( curDisplacement > 30. ) && // then object is too far away, and
( llGetForce() != < 0.0, 0.0, 0.0 > ) ) // force not already zero,
{ // then let gravity take over, and change color to green.
llSetForce( < 0.0, 0.0, 0.0 >, FALSE );
llSetColor( < 0, 1.0, 0 >, ALL_SIDES );
llSay( 0, "Force removed; object in free flight." );
}

if ( second > 1000 ) // then time to wrap this up.
{
// turn object blue and zero force to be safe....
llSetColor( < 0, 0, 1.0 >, ALL_SIDES ); // change color to blue.
llSetForce( < 0, 0, 0 >, FALSE );

// ...move object back to starting position...
// ...after saving current status of Physics attribute.
integer savedStatus = llGetStatus( 1 );
llSetStatus( 1, FALSE ); // turn physics off.
while ( llVecDist( llGetPos(), startPos ) > 0.001)
{
llSetPos( startPos );
}
llSetStatus( 1, savedStatus ); // restore Physics status.

//...and then turn color to black and Reset the script.
llSetColor( < 1, 1, 1 >, ALL_SIDES );
llSetTimerEvent( 0 ); // turn off timer events.
llSay( 0, "Done and resetting script." );
llResetScript(); // return object to ready state.
}
}
}

JoeTheCatboy Freelunch
Registered User
Join date: 14 Jun 2006
Posts: 42
12-29-2006 10:40
You can't set force on objects that the script is not in. To push other objects, you use the llPushObject method. To use llDetectedKey, you have to either have a touch event or a sensor event.
KINGR Redgrave
Registered User
Join date: 23 Dec 2006
Posts: 37
12-29-2006 14:47
THANKS FOR THE INFO,NOW MY QUESTION IS HOW WOULD PUT THIS IN THE SCRIPT AND FILL IN THE VARIABLES
CODE


llPushObject(key id, vector impulse, vector angular_impulse, integer local)

Lance LeFay
is a Thug
Join date: 1 May 2003
Posts: 1,488
12-30-2006 10:50
Capslock is sure to get a LOT of responses.

Well, that coupled with your lack of punctuation and basic sentence structure...
_____________________
"Hoochie Hair is high on my list" - Andrew Linden
"Adorable is 'they pay me to say you are cute'" -Barnesworth Anubis
JoeTheCatboy Freelunch
Registered User
Join date: 14 Jun 2006
Posts: 42
12-30-2006 11:56
llPushObject(key (the key of the target to push, usually llDetectedKey(i) or something if it is in a loop), vector force (the force in a vector, if you want to push them up (orbit) you would use <0,0,1000000> or something, in a for loop. If you wanted to push them away from you, or the object, use llRot2Fwd(llGetRot()) * 1000000), vector angular impulse (this is the angular impulse, I haven't used it much.), integer local (if this is local, or absolute axis. Local would mean that if the object were to get rotated, the axis of push would change. Absolute would mean that it would stay constant (up will always be up, for example)));

Hope that helped
KINGR Redgrave
Registered User
Join date: 23 Dec 2006
Posts: 37
12-30-2006 12:00
Cool thanks for the info, im going to try that.and Lance, if you have nothing good to say, say nothing at all.