Jump to content

LSL Physics


EduduKohler
 Share

You are about to reply to a thread that has been inactive for 1338 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

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? How can I move an object more than 10 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 that returns mass in kgs

5) In order to kreep track of the object physical parameters, like velocity, position, acceleration and force, I'm using a timer function printing these values with llSay over time, but it's not printing more than two times per second. I imagined it could be something to do with the printing function performace, but I'm not sure. Is there a better way of doing this?

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:

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:

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);
    }
}

 

Edited by EduduKohler
Link to comment
Share on other sites

34 minutes ago, EduduKohler said:

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 that returns mass in kgs

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.

1) Not sure, I'll get back to you on that one.

2) Yes, the Second Life World is measured in meters and Y is north, X is east, and Z is the up-direction.
(And in object-local coordinates, X is forward, Y is left, and Z is up.)

3) I tried your free-fall script and it seems to work correctly. This was the last round of outputs:

...
Object: Velocity=<0.00000, 0.00000, -15.24334>
Object: Acceleration=<0.00000, 0.00000, -9.80000>
Object: Force=<0.00000, 0.00000, 0.00000>
Object: Mass=0.080000
Object: I Collided With Land!
Object: Final position:<167.68760, 62.04665, 20.24062>
Object: Time elapsed:
Object: 2.126480s

4) While llGetMassMKS returns the mass of an object in kilograms, it can only be used for the object the script is in. If you want to get the mass of another object, you can use llGetObjectMass which returns the mass of any object in "lindograms," where 1 lindogram equals 100 kilograms. Multiply the value by 100 and you get the same value as llGetMassMKS.

  • Like 1
Link to comment
Share on other sites

10 minutes ago, Wulfie Reanimator said:

1) Not sure, I'll get back to you on that one.

2) Yes, the Second Life World is measured in meters and Y is north, X is east, and Z is the up-direction.
(And in object-local coordinates, X is forward, Y is left, and Z is up.)

3) I tried your free-fall script and it seems to work correctly. This was the last round of outputs:


...
Object: Velocity=<0.00000, 0.00000, -15.24334>
Object: Acceleration=<0.00000, 0.00000, -9.80000>
Object: Force=<0.00000, 0.00000, 0.00000>
Object: Mass=0.080000
Object: I Collided With Land!
Object: Final position:<167.68760, 62.04665, 20.24062>
Object: Time elapsed:
Object: 2.126480s

4) While llGetMassMKS returns the mass of an object in kilograms, it can only be used for the object the script is in. If you want to get the mass of another object, you can use llGetObjectMass which returns the mass of any object in "lindograms," where 1 lindogram equals 100 kilograms. Multiply the value by 100 and you get the same value as llGetMassMKS.

Thanks for the reply, and thanks for trying the script!
I'll try to figure out what's happening in my tests

Link to comment
Share on other sites

Applying an impulse to an object in SL is deliberately throttled to prevent certain types of griefing. llSetVelocity is more accurate. I haven't tried llSetForce.

The mass of SL objects is what they would weigh if their bounding box was full of water. Avatars weigh around 100-200Kg. Build a balance and sit on one end to test this.

There's a top speed in SL, a few hundred meters per second. There's also a rotation speed limit.

  • Like 2
Link to comment
Share on other sites

2 hours ago, EduduKohler said:

How can I move an object more than 10 meters?

Use llSetRegionPos or use llSetLinkPrimitiveParamsFast and  set its PRIM_POSITION parameter.

EDIT:  Or, of course, use llSetKeyframedMotion or llMoveToTarget

Edited by Rolig Loon
Link to comment
Share on other sites

5 minutes ago, Rolig Loon said:

Use llSetRegionPos or use llSetLinkPrimitiveParamsFast and  set its PRIM_POSITION parameter.

EDIT:  Or, of course, use llSetKeyframedMotion or llMoveToTarget

Incidentally, don't mix those. When using llSetKeyframedMotion, it can take several seconds for the keyframed motion system to take control or release control of the object. It's not interlocked with the SetPos family of functions, and using keyframe and SetPos too close together in time doesn't work well.

Nor is llSetKeyframedMotion very accurate over a chain of moves. There is cumulative error, and not just roundoff error. Move 100m with keyframe motion and you might be 1m off at the end. This gets worse in overloaded sims.

It helps to think of motion control in SL as you would real-world robotics. You get to send commands to the actuators, and then you check what happened and make corrections. This is sometimes new to people  who've never programmed in a world where they didn't have total control.

  • Like 1
Link to comment
Share on other sites

On 10/15/2020 at 5:44 AM, EduduKohler said:

5) In order to keep track of the object physical parameters, like velocity, position, acceleration and force, I'm using a timer function printing these values with llSay over time, but it's not printing more than two times per second. I imagined it could be something to do with the printing function performance, but I'm not sure. Is there a better way of doing this?

 

could write the values to a list, and then Say the values list at the end of the experiment

can run out of script memory when doing this. A way to handle this is to treat the list like a page worth of data: write_to_list > on_list_full -> say_list -> clear_list > write_to_list

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1338 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...