Richardus second DOOR script


#1

12 months later… after a long ride :blue_car:
I made a new door script, this one is doing what i wanted 12 months ago.
I tried to make it easy in setup. but still failed at few small things mabye.
I would say, try it let me know. I hope when it’s good that @caitlyn mabye want it on the examples. but let me know first. this is RC version and hosting on other place just for download.

I tried more, but it looks i do not get more out of it, need to understand some things more first. But it works very good. There are cases that the door mabye is going wonky. tried to intercept most but i think at the end it still fail.

You can find it here. https://app.box.com/s/8hbveriawyb1qmug4fsp9svt0cwfh9a4

Working on some improvements and changes.

Instruction in the script, but paste them here too.

// INSTRUCTIONS
//
//  - Place object on the location you want and set the rotation correct Y-Axis.
//    - Set the registration point x = 0.0 or 1.0 in most situations in my it where done on the Z-Axis
//    - Check the script and change if required the sound,direction etc. (line 31-33)
//    - Upload the script to ATP or other Webpage etc.
//    - copy and Paste the url inside the object. 
//    - Make sure it's loading.
//
// Note: if the position or rotation or userDataOject is changed, you need to reload the script. 
//          So the new position and rotation is read.
//
//         Before making any changes on the doro, stop the script firts. 
//         Easy way todo that is by add // in front, and remove it when done.
//
//----------------------------
//
//  RiRa_Door_201605_rc1.js
//
//  Created by Richardus Raymaker on 15-05-2016
//    Thanks to Clement and others for the extra support and help.
//
//  Creative Common Attribution 4.0 International (CC BY 4.0)
//  http://creativecommons.org/licenses/by/4.0/
//
//----------------------------
// Sounds, 
//
// https://www.freesound.org/people/rivernile7/sounds/249573/
// http://creativecommons.org/licenses/by/3.0/
//----------------------------

Entitiy! Door.script
Entitiy! Door.script
#2

Cool @Richardus, I’ll check it out!


#3

Working on some improvments @caitlyn.

Ok, New version available RC2
This version can be configured from the userData field.
So once the door is placed you not need to change the script.

Read the instructions in the script. But note it again here. do not change the doorIsOpen parameter.

Script can be downloaded from here:
https://app.box.com/s/fj22906qyvpit2wgbrhdmo222y90t6l9

Expect a RC3 too in a while.


#4

Ok. here’s my final door script for now.

Cleaned soem things up. The biggest change is that you cannot close the door manual anymore, but that way lots of problems get solved. and for the functionality it’s not a big problem. better a reliable door that stay a bit longer open then a door that is going coo coo. You can btw set the opentime between 6500ms and higher.

@Caitlyn , this one can be used in the examples if you want.

http://market.simsquaremetaverse.nl/scripts/RiRa_SimpleDoor_V1.js

I just hope people start to use doors !
Forgot that you cannot load entity scripts in the script editor. Here’s the code.

// INSTRUCTIONS
//
//  - Place object on the location you want and set the rotation correct Y-Axis.
//    - Set the registration point x = 0.0 or 1.0 in most situations in my it where done on the Z-Axis
//    - Upload the script to ATP or other Webpage etc.
//
//     - Copy this json data below to the userData field: 
//
//    {"volume":0.3,"reverse":false,"doorOpenTimeSec":15000,"doorIsOpen":false,"doorMoves":false}
//
//    Do not change the doorIsOpen and doorMoves setting in the json string.
//
//    - copy and Paste the url inside the object. 
//    - Make sure it's loading.
//
// Note: if the position or rotation or configDataOject is changed, you need to reload the script. 
//          So the new position and rotation is read.
//
//
//    JSON parameters:
//
//    - volume            = Volume for the door sound. between 0.0 - 1.0
//    - reverse            = If set to true, the door is rotating the opposite direction left vs right door.
//    - doorOpenTimeSec    = Time before the door is closing automatic. lowest setting 6500ms
//
//----------------------------
//
//  RiRa_SimpleDoor_V1.js
//
//  Created by Richardus Raymaker. 26-05-2016
//    Thanks to Clement and others for the extra support and help.
//
//  Creative Common Attribution 4.0 International (CC BY 4.0)
//  http://creativecommons.org/licenses/by/4.0/
//
//----------------------------
// Sounds, 
//
// https://www.freesound.org/people/rivernile7/sounds/249573/
// http://creativecommons.org/licenses/by/3.0/
//----------------------------

(function()
{     
    var dooropenSound = SoundCache.getSound("http://market.simsquaremetaverse.nl/sounds/dooropen_CCBY30_249573.wav");
    var doorclosedSound = SoundCache.getSound("http://market.simsquaremetaverse.nl/sounds/doorclose_CCBY30_249573.wav");
    
//-----------------------------

    function rotToDeg(rotation)
    {    
        var angle = Math.round((Quat.safeEulerAngles(rotation).y + 360.0) % 360.0);
        return angle;
    }    
    
    function setDoorProperties(setrot, rotation, angvelocityY, angdamping, damping, friction, configJsonData)
    {
        if (setrot==true) 
        {
            var newProperties = 
            {
                rotation: rotation,
                angularVelocity: Quat.fromPitchYawRollDegrees(0,angvelocityY,0),
                angularDamping: angdamping,            
                damping: damping,
                friction: friction,
                userData: JSON.stringify(configJsonData)                    
            };            
        }
        else
        {
            var newProperties = 
            {
                angularVelocity: Quat.fromPitchYawRollDegrees(0,angvelocityY,0),
                angularDamping: angdamping,            
                damping: damping,
                friction: friction,
                userData: JSON.stringify(configJsonData)                        
            };    
        }        
        Entities.editEntity(Ent, newProperties);    
    }
    
    function movedoor()
    {            
        if (!configDataOject.doorMoves)
        {
            var angvelY;    
            if (!configDataOject.doorIsOpen)
            {
                if (!configDataOject.reverse) { angvelY = 108; } else { angvelY = -108; }
                Audio.playSound(dooropenSound, { loop: false, position: basepos ,volume: configDataOject.volume });    
                var OpenTimeSec=configDataOject.doorOpenTimeSec;
                if (OpenTimeSec<6500) OpenTimeSec=6500;
                timerAutoClose=Script.setInterval(autoDoorClose, OpenTimeSec);        
            }
            else
            {
                if (!configDataOject.reverse) { angvelY = -108; } else { angvelY = 108; }    
            }    
                    
            configDataOject.doorMoves = true;            
            setDoorProperties(false, baserot, angvelY,0.40,0.0,0.0, configDataOject);        
            timerDoor=Script.setInterval(checkrotation,10);        
        }
    }        
    
    function autoDoorClose()
    {    
        configDataOject.doorMoves =    false;
        configDataOject.doorIsOpen=true;        
        Script.clearInterval(timerAutoClose);    
        movedoor();    
    }                

    function checkrotation()
    {
        var target;
        var doorclosedangle;
        var data = Entities.getEntityProperties(Ent, ["rotation"]);
        var currentrot = rotToDeg(data.rotation);        
        
        if (!configDataOject.reverse) 
        {     
            target = baserot + 88; 
            doorclosedangle = 87;    
        } 
        else 
        { 
            target = baserot - 88; 
            doorclosedangle = 89;
        }
        
        var signedDistance = (target - currentrot) % 360;    
        if ((Math.abs(signedDistance) < 5) && (!configDataOject.doorIsOpen))            
        {            
            configDataOject.doorIsOpen=true;
            configDataOject.doorMoves =    false;            
            if (!configDataOject.reverse) { setDoorProperties(false, baserot, -2,0.2,0.9,0.9, configDataOject); }
                else { setDoorProperties(false, baserot, 2,0.2,0.9,0.9, configDataOject);}            
            Script.clearInterval(timerDoor);
        }
        else if ((doorclosedangle < Math.abs(signedDistance)) && (configDataOject.doorIsOpen))
        {        
            Script.clearInterval(timerAutoClose);    
            Script.clearInterval(timerDoor);
            configDataOject.doorIsOpen=false;
            configDataOject.doorMoves =    false;                
            setDoorProperties(true, baserot, -0.1,0.2,0.9,0.9, configDataOject);                    
            Audio.playSound(doorclosedSound, { loop: false, position: basepos ,volume: configDataOject.volume });        
            var newProperties = {position: basepos};
            Entities.editEntity(Ent, newProperties);        
        }            
    }    

    this.clickDownOnEntity = function(entityID, mouseEvent) 
    { 
        Ent = entityID;    
        var userData = Entities.getEntityProperties(Ent, ["userData"]).userData;    
        configDataOject = JSON.parse(userData);
        
        var copyEnt = Entities.getEntityProperties(Ent, ["rotation","position"]);
        var jsonEnt = JSON.stringify(copyEnt);
        var data = JSON.parse(jsonEnt);    
                
        if (init)
        {
            baserot = rotToDeg(data.rotation);
            basepos = data.position;
            init=false;
            configDataOject.doorMoves=false;
            configDataOject.doorIsOpen=false;
            setDoorProperties(false, baserot, 0,0.0,0.0,0.0, configDataOject);
        }        
        if (!configDataOject.doorIsOpen) {movedoor();}
    };
    
    var configDataOject;
    var Ent;
    var timerDoor;
    var    timerAutoClose;
    var doorMoves = false;    
    var init = true;
    var baserot;
    var basepos;    
}
)

#5

Hello!
I tried this script. It works intermittently. Is there an updated working version?


#6

I have not looked at the script fir long time.
I think your problem is that it’s not always closing correct ? or open ?

And i have seen something on this forum with keyframes i think. That would make a better door i think. This script i made is very old.

Not have quick time for it i think to look at it.


#7