Entitiy! Door.script


#1

Ok, i give my first version of my door script here. so it can be used. The entity editor annoyed me to much to work further on it. still missing the X and Z movement arrows, moving with the mouse is good for a pile of yelling.

Anyway, here’s the door script.
Upload the script to some hosting space and place the url inside the entitiy script.

Script comes in few minutes.


#2
//
//  Entity-Door.js V0.03
//
//  Created by Richardus Raymaker on 04-09-2015

//  Distributed under the Apache License, Version 2.0.
//  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//

(function() 
{ 
    var doorAngle = 90;
    var doorstep = 0.5;
    
    var doorIsOpen = false;
    var stopMove = true;
    var doorEntityID;    
    var i = 0;
    var pitch = 0.0;
    var yaw = 0.0;
    var roll = 0.0;    
    
    function movedoor(deltaTime)
    {
        if (!stopMove)
        {
            if (!doorIsOpen)
            {            
                i=i+doorstep;
                if (i<=90) 
                {      
                        rotation = Quat.fromPitchYawRollDegrees(pitch, yaw+i, roll);    
                        var newProperties = 
                        {
                            rotation:     rotation,
                        };    
                        Entities.editEntity(doorEntityID, newProperties);
                }
                else 
                {
                    doorIsOpen=true;
                    stopMove=true;
                    Script.update.disconnect(movedoor);
                }
            }
            else if (doorIsOpen)
            {            
                i=i-doorstep;
                if (i>=0) 
                {      
                        rotation = Quat.fromPitchYawRollDegrees(pitch, yaw+i, roll);    
                        var newProperties = 
                        {
                            rotation:     rotation,
                        };    
                        Entities.editEntity(doorEntityID, newProperties);
                }
                else 
                {
                    doorIsOpen=false;
                    stopMove=true;
                    Script.update.disconnect(movedoor);
                }
            }    
        }
    }        

    this.clickDownOnEntity = function(entityID, mouseEvent)
   {    
      if (!doorIsOpen)
      {
            doorEntityID=entityID;
            stopMove=false;
            Script.update.connect(movedoor);
      }
      else
      {
            doorEntityID=entityID;
            stopMove=false;    
            Script.update.connect(movedoor);
      }
   } 
})

#3

Hi @Richardus.Raymaker do you have door fbx you are using? Or the location I can go to test?


#4

Hi chris,

I used for the test a simple entity box. sized to 0.05 x 2.10 x 0.90
Not have a good door available, the old one is not good.

Not made a door object, only the script right now.


#5

@Richardus Raymaker Is there a way to set the rotation point  when using your door opener script?
entityDoor.js

In Blender you can change an Object’s Origin and hence Axis of Rotation
It can be set to any vertex or group of vertices in a Blender object
eg. Default Cube .> Edit Mode
.> Select any two vertices on a vertical edge
.>  SHIFT+S
.>  'Cursor to selected’
then
.>  Object Mode
.>  CTRL+ALT+SHIFT+C
.> ‘Origin to 3D Cursor’

Unfortunately the new origin doesn’t export to HiFi in the .fbx (?)
Can ‘Change Origin’ be addressed in the Entity ?
Is there a .js somewhere?
or will we have use ‘Rotate Around Parent’ and have to make doors  as with LSL and use two Entities?


#6

This origin problem comes up a lot in virtual worlds. All the import functions set the origin to the center of the mesh part(s). I just add a zero-dimension extension to the door to force the ‘center’ of the visible part to be its edge. Like this:


#7

You can change the origin point in any entity by changing the Registration.

If you make a box for a door and make the x = 1M wide and the y = 2M high and the z = 0.1M thick
Then change the Registration for the X to either zero or one, the pivot point will move to the edge and will swing like a door if you rotate it.

Default has registration at 0.5 which is center, changing the x value to zero moves the point to the far left and changing x to 1 moves the pivot point to the far right.
This is the same for all 3 axes, setting all to 1 or 0 will result in the pivot point being at one corner.


#8

High Fidelity have a perfect solution for that in the entity properties Look for the registration point.


#9

manually updating the rotation frequently like that can cause stuttering issues – when someone clicks on it, you should just give it angular velocity. we interpolate smoothly in the physics engine this way. then, when someone clicks on it again, give it angular velocity the other way. you can check in your update loop to see if the door rotation is either ‘fully open’ or ‘fully closed’ and then zero out its angular velocity.

if another user comes and clicks it while its opening, check for the current angular velocity and then swap if you want the door to start shutting, and vice versa

i was looking here to see what your userData problem was, but you’re not using userData. that doorIsOpen variable is local to this entity script on each users machine, so yeah you’ll run into problems trying to keep state there (the toggle) if you send your updated script i can try to help.

but you shouldn’t really need userData with a pattern like this – your ‘shared state’ is knowledge about the angular velocity – that’s already kept in sync by the entity server. so instead of making up a variable for ‘open’ and ‘closed’, just check whether the angular velocity is in the ‘open’ or ‘closed’ direction and whether its current rotation is ‘open’ or ‘closed’

best!


#10

This is old topic… The latest door can be found here.

https://forums.highfidelity.com/t/richardus-second-door-script/10853

And, i keep the manual door close out of it for now. Because there to many problems with it. auto close works fine to.


#11

so yeah you’re heading toward the pattern i suggested – i’d just recommend removing userdata completely, and never manually setting the rotation. figure out your initial conditions, on click get properties and read the current rotation and current angular velocity to determine the state: open, closed, opening, or closing. then take action as appropriate.


#12

Yes, in this case, I too recommend you only need to remember two things, the closed rotation and the opened rotation. Well, three if you want to be nice: the length of time for the door swing (t). Those would be user settable data elements. The script then can determine the rotation angle, apply the proper angular velocity to make the door swing in time t, monitor its progress to stop the door swing when it is close enough to the target rotation.


#13

Well, i posted my script. and i keep it that way.
userData is important to keep in, because you not want to change everytime scripts and upload many copies of the same script because a small change between doors.

Only thing i use is the start position and rotation. other parameters are fixt set. Well. you can always make or change it. It sounds easy to make ., but it’s not.


#14

a script like this is simple and should work, although i havent tested it. use userdata for your sound or color or whatever but you’re not really using it in a good way for this use case. i’ve left it as an exercise for you to initialize in the preload with the current rotation of whatever arbitrary object and then add your start and end rotations to that initial one to abstract it.

i am sure you’ve done a bunch work on your script but i think you may want to start over from a cleaner slate.

//@imgntn james b. pollack 5/26/2016

edit: see below for script


#15

i wouldn’t keep time state in the door… i mean, that would work for one person, but my door doesn’t know that your door is two seconds into its timeout, unless you store that in userdata (don’t). i normally dont advocate putting much in update loops, but here the door itself can check to see if its open, closed, opening, or closing. so in your update loop, just check that stuff!

best!


#16

That script is going to be a fail. I solved it already with a new script. except one thing.
Also it need to be easy to use. and current script is easy to use.


#17

oh yeah? why a fail?


#18

Make one, and you will find many side effects. also your missing a timer so you never know the door rotation. It’s not secondlife… it’s high fidelity that need a different way.

But you can always write one yourself and post it.


#19

edit: see below for script


#20

Did you looked at the second door script ? this door script is one year old and replaced. Your posting and looking in the wrong topic at the wrong script. Already 2 script ahead of this one in the topic.

And i have tested many combinations.