Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0002818opensim[REGION] Physics Enginespublic2008-12-13 09:042011-07-18 03:54
Reportermirceakitsune 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusconfirmedResolutionreopened 
PlatformPentium 4OSWindows XP Media CenterOS VersionSP3 32bit
Product Version 
Target VersionFixed in Version 
Summary0002818: ODE - Rezzing a physical object with llRezObject at a certain velocity makes that object go back and forth / physics lag
DescriptionI tried a simple two prim gun with the LL grid popgun script for both the bullet and gun scripts. I found an issue where in ODE, rezzing a bullet or any physical prim with llRezObject at a high velocity causes that physical prim to keep jumping back and forth between some positions.

For example, lets say the avatar is holding a classic weapon which shoots a physical prim for a bullet. He then fires and the bullet rezzes in front of him with a fast velocity as its set to have in llRezObject. The bullet passes 10 meters thrown away correctly, then gets to 20 meters, and after that it gets even further to 30 meters. But when it reaches 30 meters, it suddenly jumps back to where it was at 20 meters, then with the same velocity goes again towards 30 meters, then when reaching 30 meters it resets to the same 20 meters again and so on, looping like that forever.

Apparently this is some sort of physics engine lag. The flying primitive suddenly catches a certain position and its velocity there while being physical, then after running by a bit further it returns to that position, basically going back in time to where it was each 0.25 seconds or so forever.
TagsNo tags attached.
Git Revision or version number
Run Mode Grid (1 Region per Sim)
Physics EngineODE
Script Engine
Environment.NET / Windows32
Mono VersionNone
Viewer
Attached Filesrar file icon Physics lag.part1.rar [^] (1,457,664 bytes) 2008-12-14 03:11
rar file icon Physics lag.part2.rar [^] (681,134 bytes) 2008-12-14 03:12

- Relationships
child of 0003987acknowledged [ODE] 

-  Notes
(0007860)
Teravus (administrator)
2008-12-13 23:34

Sorry, I need the exact situation, scripts included to debug this.

Verbal descriptions are not going to work.

Setting this to feedback. If I don't see any activity here, I'm going to close it as won't fix.
(0007880)
mirceakitsune (reporter)
2008-12-14 02:20
edited on: 2008-12-14 03:13

Sure... these are the two scripts from the popgun on the LL grid, the first one being the popgun bullet script and the second the gun script. My test was rezzing two prims, making one physical, putting the bullet script in it, taking it in inventory, dragging it into the other prim from my inventory, putting the gun script into that other prim as well next to the physical prim, took that prim into my inventory as well and attached it to my avatar, then entered mouselook and shot by left clicking.

The bullet shot but on its way it causes the specified behavior, and keeps going back in time every 0.5 seconds with the same speed and direction, lagging between two positions.

[EDIT] Squeezed in a small video of the issue and what exactly happens. Attached it as a .rar archive of two parts.

-------------- BULLET SCRIPT --------------

//
// Popgun Bullet
//
// Becomes non-physical on impact, makes a little particle system, then fades away.
//

integer fade = FALSE;
float alpha = 1.0;

splat()
{
        llSetStatus(STATUS_PHANTOM, TRUE);
        vector pos = llGetPos();
        llMoveToTarget(pos, 0.3); // Move to where we hit smoothly
        llSetColor(<0,0,1>, ALL_SIDES);
        llTriggerSound("splat4", 1.0);
        //llMakeFountain(50, 0.3, 2.0, 4.0, 0.5*PI,
                        //FALSE, "drop", <0,0,0>, 0.0);
        fade = TRUE;
        llSetTimerEvent(0.1);
}
default
{
    state_entry()
    {
        llSetStatus( STATUS_DIE_AT_EDGE, TRUE);
    }
    
    on_rez(integer delay)
    {
        llSetBuoyancy(1.0); // Make bullet float and not fall
        llCollisionSound("", 1.0); // Disable collision sounds

        if (delay > 0)
        {
            llSetTimerEvent((float)delay); // Time until shot deletes itself
        }
    }

    collision_start(integer total_number)
    {
        splat(); // When we hit something, go spat!
    }
    land_collision_start(vector pos)
    {
        splat(); // When we hit the ground, go splat!
    }
    
    timer()
    {
        if (!fade)
        {
            llDie();
        }
        else
        {
            // Slowly turn transparent, then go away.
            llSetAlpha(alpha, -1);
            alpha = alpha * 0.95;
            if (alpha < 0.1)
            {
                llDie();
            }
        }
    }
}

-------------- GUN SCRIPT --------------

//
// Popgun
//
// This script is a basic gun- it waits for a mouseclick in mouselook and
// then fires a bullet in the direction the user is facing.
// It also animates the avatar holding it, to create a convining hold and
// firing look for the gun.
//
// This script can be used as a good basis for other weapons.
//

float SPEED = 20.0; // Speed of arrow in meters/sec
integer LIFETIME = 7; // How many seconds will bullets live
                                    // before deleting themselves
float DELAY = 0.2; // Delay between shots to impose

vector vel; // Used to store velocity of arrow to be shot
vector pos; // Used to store position of arrow to be shot
rotation rot; // Used to store rotation of arrow to be shot

integer have_permissions = FALSE; // Indicates whether wearer has yet given permission
                                    // to take over their controls and animation.
                                    
integer armed = TRUE; // Used to impose a short delay between firings

string instruction_held_1 = "Use Mouselook (press 'M') to shoot me.";
string instruction_held_2 = "Choose 'Detach' from my menu to take me off.";
                                    // Echoed to wearer when they are holding the bow
string instruction_not_held = "Right-click (apple-click) me, and choose More > Wear' from the menu to use me.";
                                    // Echoed to toucher if not worn
                                    

fire()
{
    //
    // This subroutine creates and fires an arrow
    //
    if (armed)
    {
        //

        // Actually fires the arrow
        //
        armed = FALSE;
        rot = llGetRot(); // Get current avatar mouselook direction
        vel = llRot2Fwd(rot); // Convert rotation to a direction vector
        pos = llGetPos(); // Get position of avatar to create arrow
        pos = pos + vel; // Create arrow slightly in direction of travel
        pos.z += 0.75; // Correct creation point upward to eye point
                                        // from hips, so that in mouselook we see arrow
                                        // travelling away from the camera.
        vel = vel * SPEED; // Multiply normalized vector by speed
        
        //llStartAnimation("shoot_R_handgun"); // Trigger the bow release animation
        llTriggerSound("shoot", 1.0); // Make the sound of the arrow being shot
        llRezObject("bullet", pos, vel, rot, LIFETIME);
                                            // Create the actual arrow from object
                                            // inventory, and set its position, velocity,
                                            // and rotation. Pass a parameter to it to
                                            // tell it how long to live.
                                            
        llSetTimerEvent(DELAY); // Wait until can fire again
    }
}

default
{
    state_entry()
    //
    // This routine is called whenever the script is edited and restarted. So if you
    // are editing the bow while wearing it, this code will re-request permissions
    // to animate and capture controls.
    //
    {
        if (!have_permissions)
        {
            llRequestPermissions(llGetOwner(),
                PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS);
        }
    }
    on_rez(integer param)
    {
        //
        // Called when the gun is created from inventory.
        //
        llPreloadSound("shoot"); // Preload shooting sound so you hear it
    }

     run_time_permissions(integer permissions)
    {
        //
        // This routine is called when the user accepts the permissions request
        // (sometimes this is automatic)
        // so on receiving permissions, start animation and take controls.
        //
        if (permissions == PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS)
        {
            if (!have_permissions)
            {
                llWhisper(0, instruction_held_1);
                llWhisper(0, instruction_held_2);
            }
            llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
            llStartAnimation("hold_R_handgun");
            have_permissions = TRUE;
        }
    }

    attach(key attachedAgent)
    {
        //
        // If attached/detached from agent, change behavior
        //
        if (attachedAgent != NULL_KEY)
        {
            // Bow has been attached or rezzed from inventory, so
            // ask for needed permissions.
            llRequestPermissions(llGetOwner(),
                PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS);
        }
        else
        {
            // Bow has been detached from avatar, so stop animation and release controls
            if (have_permissions)
            {
                llStopAnimation("hold_R_handgun");
                llStopAnimation("aim_R_handgun");
                llReleaseControls();
                llSetRot(<0,0,0,1>);
                have_permissions = FALSE;
            }
        }
    }

    control(key name, integer levels, integer edges)
    {
        // This function is called when the mouse button or other controls
        // are pressed, and the controls are being captured.
        //
        // Note the logical AND (single &) used - the levels and edges
        // variables passed in are bitmasks, and must be checked with
        // logical compare.
        //
        // Checking for both edge and level means that the button has just
        // been pushed down, which is when we want to fire the arrow!
        //
        if ( ((edges & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON)
            &&((levels & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON) )
        {
            // If left mousebutton is pressed, fire arrow
            fire();
        }
    }
    
    touch_start(integer num)
    {
        // If touched, remind user how to enter mouselook and shoot
        if (have_permissions)
        {
            llWhisper(0, instruction_held_1);
            llWhisper(0, instruction_held_2);
        }
        else
        {
            llWhisper(0, instruction_not_held);
        }
    }
    
    timer()
    {
        // After timer expires, allow user to shoot bow again
        llSetTimerEvent(0.0);
        armed = TRUE;
    }
  
}

(0008836)
mirceakitsune (reporter)
2009-01-16 17:47

This issue is still happening the same way in rev. 8066.
(0008848)
idb (manager)
2009-01-18 06:50

There is a change in 8072 that should fix the object dropping before moving problem.

Is the "jumping back" problem still happening? I have not been able to reproduce that part of the mantis yet.

I have set it to fixed for the dropping problem, reopen if the "jumping back" still happens.
(0008849)
mirceakitsune (reporter)
2009-01-18 08:30

I have tested again in the latest revision of 8072 and the problem still exists. The scripts are the same ones I posted above and the issue seems to be mostly unchanged from last time although it is happening slightly differently. Steps to reproduce are the same as before, the gun script in an attached prim and the bullet script in the physical prim it throws, ODE + Meshmerizer with xEngine scripting in a region running one sim only.

Difference I think I noticed from last time: The back and forth lag only takes place when the rezzed physical prim hits another primitive on its way which changes its trajectory. If the prim is only thrown over terrain it then just lag out to infinity towards the direction the terrain pushes it to (not normal either as the prim should initially fall to the ground sooner or later unless it has a llSetBuoyancy(1) override). Once again my test bullet is a sphere in shape.

I also tried rezzing a 3 x 3 x 3 physical box on the ground and shooting it with the test weapon. When the bullet hit it the box was not moved any bit while the bullet remained stuck to its surface or started doing back and forth lag around there. Sometimes the bullet also looks as if it's teleported near that primitive rather then getting there by being thrown, although that may probably be the fast velocity.
(0008850)
Teravus (administrator)
2009-01-18 08:52

Taoki, can you put a position printer to test if this is actually moving back and forth. Often times the client interpolation makes it 'look' like it's moving back and forth, but it actually isn't. Use a text printer such as llSay(llGetPos()). The reason I ask, is because the same exact thing happens when avatars move and the lag is high. This is called rubberbanding and isn't physics related at all.
(0008851)
mirceakitsune (reporter)
2009-01-18 09:51

Finished testing that Teravus. As stupid as I feel for not realizing this earlier, the problem causing the back and forth loop was something in the popgun bullet script. With a physical sphere that doesn't contain any scripts this issue does not happen and the thrown primitive just stops into the object it collides with and falls as it should. However, even with no script in it the bullet still floats away to infinity if thrown over terrain or bouncing too hard from another prim, so that is a separate issue which takes place regardless of any script being present or not.

I'm not sure which part of the popgun bullet script causes this, I tried commenting out llMoveToTarget but that didn't fix it. Either way I still tested the position using a bullet containing both the popgun bullet script and this script:

default
{
    state_entry()
    {
        llSetTimerEvent(0.25);
    }
    timer()
    {
        vector position = llGetPos();
        llSay(0, "Primitive position:" + (string)position);
    }
}

The returned position was always the same even while the bullet still went back and forth.
(0008852)
Teravus (administrator)
2009-01-18 13:05

Hmm, potentially, the velocity isn't getting reset? If it moves back and forth, the client may be interpolating it until an update happens.. which puts it back where it is on the server, then the client interpolates it again.. (repeatedly?)
(0008855)
master zephyr (reporter)
2009-01-18 16:47
edited on: 2009-01-18 16:54

I tryed it, its what he said but also old stuff. My sl cannons work fine, other than physics problem , dont know.
We had to tweek a few things for OSG or we get what thay said
.
Whats wrong is not script, its physics. The scripts are fine!

                     Master (Fires a cannon) zephyr :)
PS: if we cant have cars yet at least let guns work and dammage there of. Keeps the ppl happy.

(0008856)
Teravus (administrator)
2009-01-18 16:56

Do you think you're actually helping with a note like that master zephyr? Did you try the llSay((string)llGetPos())? No? oh well. You're not helping.
(0018957)
makopoppo (manager)
2011-07-18 03:54

Tested on current opensim 0.7.2-dev, the issue still exists. More precisely, it occurs when the bullet is hitting on the target (ex.avatar). If the target is out of the way, it doesn't occur.

I'm not sure if the developers who has been walking on this issue is still active now (this issue is over two years ago!). I unassigned and change the status so that current developer can easily find it as undone task.

- Issue History
Date Modified Username Field Change
2008-12-13 09:04 mirceakitsune New Issue
2008-12-13 09:04 mirceakitsune SVN Revision => 7684
2008-12-13 09:04 mirceakitsune Run Mode => Grid (1 Region per Sim)
2008-12-13 09:04 mirceakitsune Physics Engine => ODE
2008-12-13 09:04 mirceakitsune Environment => .NET / Windows32
2008-12-13 23:34 Teravus Note Added: 0007860
2008-12-13 23:34 Teravus Status new => feedback
2008-12-14 02:20 mirceakitsune Note Added: 0007880
2008-12-14 02:23 mirceakitsune Note Edited: 0007880
2008-12-14 03:11 mirceakitsune File Added: Physics lag.part1.rar
2008-12-14 03:12 mirceakitsune File Added: Physics lag.part2.rar
2008-12-14 03:13 mirceakitsune Note Edited: 0007880
2009-01-16 17:47 mirceakitsune Note Added: 0008836
2009-01-18 06:50 idb Note Added: 0008848
2009-01-18 06:51 idb Mono Version => None
2009-01-18 06:51 idb Status feedback => resolved
2009-01-18 06:51 idb Resolution open => fixed
2009-01-18 06:51 idb Assigned To => idb
2009-01-18 08:30 mirceakitsune Status resolved => feedback
2009-01-18 08:30 mirceakitsune Resolution fixed => reopened
2009-01-18 08:30 mirceakitsune Note Added: 0008849
2009-01-18 08:52 Teravus Note Added: 0008850
2009-01-18 09:51 mirceakitsune Note Added: 0008851
2009-01-18 12:48 idb Status feedback => assigned
2009-01-18 13:05 Teravus Note Added: 0008852
2009-01-18 16:47 master zephyr Note Added: 0008855
2009-01-18 16:54 master zephyr Note Edited: 0008855
2009-01-18 16:56 Teravus Note Added: 0008856
2009-08-09 05:56 Fly-Man- Relationship added child of 0003987
2011-07-18 03:54 makopoppo Note Added: 0018957
2011-07-18 03:54 makopoppo Assigned To idb =>
2011-07-18 03:54 makopoppo Status assigned => confirmed


Copyright © 2000 - 2012 MantisBT Group
Powered by Mantis Bugtracker