# lsl Scripting physics

#### CoolerDud

##### New member
Hello guys, I'm trying to make some physics experiments with SL engine for a Uni project, and I could use some help with some things:

1) What's the best way of getting an object initial velocity after applying an impulse to it using llApplyImpulse? I've tried using the 'start_moving()' event but it never triggers, and I don't know why. If this is not possible with llApplyImpulse, for some reason, what's the best way I could simulate something like an oblique launch, in which I apply a momentary force to an object in two axis? I'm currently trying to keep track of these parameters using a timer, but I think the results are not that reliable.

2) Is the difference between two llGetPos() coordinates in meters?

3) I have a script that moves an object 10 meters up and then keeps track of its velocity during the fall. When I try to track its acceleration with llGetAccel it always returns <0,0,0>, why is that? I was expecting something like <0,0,-9.8> after reading the wiki.

4) For my simulations it would be nice to have objects mass expressed in kg. By reading the wiki I can't understand properly how the Lg metric works. What's the best way of 'converting' Lg to Kg? EDIT: Just realized there's a function called llGetMassMKS

Most of my doubts are about the relation between LSL units and real life units. I've read the wiki several times but I'm struggling to get these values properly inside the Sim.

My goal here is to make physics tests such as free fall, oblique launch and collisions in the SL Sim and compare the results with the mathematical formulas for each behaviour. To achieve this I need to have proper values in metric system like initial velocity, distance, acceleration, mass. Could you guys give me some help with this?

Thank you!!!

These are the scripts I'm using for now:

FREE FALL:

Code:
``````float end = 0.0;

float start = 0.0;

default

{

state_entry()

{

llSetStatus(STATUS_PHYSICS, TRUE);

}

touch_end(integer num_detected)

{

llSetTimerEvent(0.1);

llSetPos(llGetPos() + <0,0,10>);

start = llGetTime();

vector initialAccel = llGetAccel();

llSay(0, "Initial position:"+(string)llGetPos());

}

land_collision_start(vector pos) {

end = llGetTime();

llSetTimerEvent(0.0);

llSay(0,"I Collided With Land!");

llSay(0, "Final position:"+(string)pos);

llSay(0, "Time elapsed:");

float elapsed = end - start;

llSay(0, (string)elapsed+"s");

}

timer()

{

llSay(0, "Velocity="+(string)llGetVel());

llSay(0, "Acceleration="+(string)llGetAccel());

llSay(0, "Force="+(string)llGetForce());

llSay(0, "Mass="+(string)llGetMass());

llSetText(

"Script=teste_queda \n"+

"Velocity="+(string)llGetVel()+"\n"+

"Acceleration="+(string)llGetAccel()+"\n"+

"Force="+(string)llGetForce()+"\n"+

"Mass="+(string)llGetMass()+"\n",

<1,1,1>, 1);

}

}``````
OBLIQUE LAUNCH:

Code:
``````float initialTime = 0.0;

float finalTime = 0.0;

vector initialPos;

vector finalPos;

default

{

state_entry()

{

llSetStatus(STATUS_PHYSICS, TRUE);

}

touch_end(integer num_detected)

{

llSay(0, "TEST START");

llSetStatus(STATUS_PHYSICS, TRUE);

llSetTimerEvent(0.05);

vector impulse = <0,10,10>;

initialTime = llGetTime();

initialPos = llGetPos();

llApplyImpulse(impulse, 0);

llSay(0,"INITIAL POSITION: "+(string)llGetPos());

}

moving_start() {

llSay(0,"INITIAL VELOCITY: "+(string)llGetVel());

}

land_collision_start(vector pos) {

finalTime = llGetTime();

finalPos = llGetPos();

llSetTimerEvent(0.0);

vector distanceTraveled = finalPos - initialPos;

float timeElapsed = finalTime - initialTime;

llSay(0, "Distanced traveled:"+(string)distanceTraveled);

llSay(0, "Time elapsed:"+(string)timeElapsed+"s");

}

timer()

{

llSay(0, "Velocity="+(string)llGetVel());

llSay(0, "Position="+(string)llGetPos());

llSetText(

"Script=teste_queda \n"+

"Velocity="+(string)llGetVel()+"\n"+

"Acceleration="+(string)llGetAccel()+"\n"+

"Force="+(string)llGetForce()+"\n"+

"Mass="+(string)llGetMass()+"\n",

<1,1,1>, 1);

}

}``````

Last edited:

#### Innula Zenovka

##### Nasty Brit
VVO Supporter 🍦🎈👾❤
1) Try something like this

Code:
``````default {
touch_end(integer num_detected) {
llSetStatus(STATUS_PHYSICS,TRUE);
llApplyImpulse(<0.0,0.0,20.0>,TRUE);//shoot up in the air
}

moving_start() {
llOwnerSay((string)llGetVel());
}
}``````
2) Yes.

3) Try this

Code:
``````default {

touch_end(integer num_detected) {
vector vPos= llGetPos();
vPos.z+=10.0;
llSetPos(vPos);
llSetStatus(STATUS_PHYSICS,TRUE);
llSetTimerEvent(0.1);

}

timer() {
llOwnerSay((string)llGetAccel());
}

land_collision(vector pos) {
llSetTimerEvent(0.0);
llSetStatus(STATUS_PHYSICS, FALSE);
}

}``````