GridTalk.de
Aufzug Script - Druckversion

+- GridTalk.de (https://www.gridtalk.de)
+-- Forum: Werkstatt (https://www.gridtalk.de/forumdisplay.php?fid=4)
+--- Forum: Technik (https://www.gridtalk.de/forumdisplay.php?fid=25)
+--- Thema: Aufzug Script (/showthread.php?tid=4610)



Aufzug Script - Xenos Yifu - 15.04.2023

Moin, hat jemand eine Idee, wie man das Ruckeln aus dem Script bekommt?
Die Bewegung ist alles andere als sanft gleitend.

PHP-Code:
// Menu controled on sit. Can also be controlled with local chat eg: /33 Floor2

integer CHANNEL = 36; // dialog channel
list MENU_MAIN = ["down","up"]; // the main menu
float BOTTOM = 20.60; // set platform ground floor height
float FLOOR_HEIGHT = 6.1; // alter to suit floor spacing
float SPEED = 0.4; 
float target;
string sound = "ba0101f0-e6da-43cc-a33b-61c172cbfebc";


default
{
    
state_entry()
    {
 
        
llListen(CHANNEL, "", NULL_KEY, "");
        
llSitTarget(<0.0, 0.0, 0.95>,ZERO_ROTATION);
        
llSetText("Sit",<0.2,0,0>,0.79);
        
target = BOTTOM;
        
llStopAnimation("sit");
        
llStopSound();
    }
   
    
listen(integer channel, string name, key id, string message)
    {
        
integer idx = llListFindList(MENU_MAIN, [message]);
        if( 
idx!=-1 )
        {
                      
llLoopSound(sound, 1.0);
//            llSay(0,"Elevator heading " + message + "." );
            
target = BOTTOM + (idx*FLOOR_HEIGHT);
            
state moving;
        }
    }


    
changed(integer change) 
    {
        if (
change & CHANGED_LINK) 

        { 
       
        
key av = llAvatarOnSitTarget();

       if (
av !=NULL_KEY)

//          if((llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) && llGetPermissionsKey() == av)

            
        
{
        
//          llStopAnimation("sit");
//          llStartAnimation("vb stand_5arms up p2");
          
llPlaySound(sound, 1.0);
          
llDialog(av, "Where to?", MENU_MAIN, CHANNEL);       
        }
        
        else
       {
           
llStopSound();

//            llRequestPermissions(av, PERMISSION_TRIGGER_ANIMATION); 
                      
        
}  
   
    }
}
}

state moving
{
   
   
    
state_entry()
    {
        
llSetTimerEvent(0.1);
    }
   
    
timer()
    {

        
llSleep(0.25); // just to stop things happening instantly.        
        
vector pos = llGetPos();

       
        if( 
pos.z!=target )
        {
            if( 
pos.z>target )
            {
                
pos.z = pos.z - SPEED;
            }
            else
            {
                
pos.z = pos.z + SPEED;
            }
        }
       
        if(  
llFabs(pos.z - target) < SPEED )
        {
            
pos.z = target;
            
llSetTimerEvent(0);
            
llSetPos(pos);
//          llSay(0,"Elevator has reached its target." );
            
state default;
        }   
       
        
llSetPos(pos);
       
    }
} 



RE: Aufzug Script - Anachron - 15.04.2023

Ich sehe keine Notwendigkeit, in die Bewegungsschleife einen Waitstate einzubauen:

llSleep(0.25); // just to stop things happening instantly.

Warum sollte das "instantly" ablaufen?
Die Bewegung wird doch über das Timer-Event getaktet.
Bau die Zeile einfach mal versuchsweise raus.


RE: Aufzug Script - Xenos Yifu - 15.04.2023

.... ich probiere es später und berichte, danke.


RE: Aufzug Script - Xenos Yifu - 15.04.2023

Das Ruckeln bleibt, einzig, ich nehme mir die Möglichkeit die Geschwindigkeit zu regulieren.


RE: Aufzug Script - Anachron - 16.04.2023

Die Geschwindigkeit sollte über den Timer-Interval zu steuern sein:
llSetTimerEvent(0.1);

Ausserdem ist da der Faktor SPEED zuständig
float SPEED = 0.4;
der die Schrittweite der Bewegung steuert ...

0.4 m / 0.1 s gibt dann ca. 4m/s ...

Wobei eine Schrittweite von 40cm schon von sich aus heftige Sprünge macht ... vielleicht mal da dran drehen?


RE: Aufzug Script - Xenos Yifu - 16.04.2023

.... ich schraube mal dran Big Grin


RE: Aufzug Script - Xenos Yifu - 18.04.2023

Ich habe llSleep(0.25); // just to stop things happening instantly. auskommentiert und
float SPEED = 0.4; auf 0,02 geändert.
Ein Kompromiss, nicht perfekt, aber deutlich besser.