Is the sit script ready for placing in other chairs


#1

Like @Caitlyn talked about not long ago to add the sit script in other chairs. The idea is good and fine

But is the script ready for it ?
Where can we find the script if it’s ready ?

ANd then we need to see if there are adjustments needed…


#2

The script should be live on the marketplace.
I do plan to make further changes to the script.
I have noticed there might be some edge cases that are not handled correctly yet, I was waiting for more test feedback.You should be fine to use it, if there’s any fixes that can be made I’d be happy to make changes.


#3

Yes, it is on the marketplace on the chair I recently uploaded. It definitely can still use some work, of course, because it is deceptively complicated, but it’s really come along way and is incredibly awesome.


#4

I want to be able to take the script/s from this kitchen chair and put it into other chairs.

Upon further inspection there seems to be several working parts, the chair itself has user data and a script URL, but also there is a collider entity which has user data and a script URL.

Can I please get some advice on how to use this script in another chair or if this is even possible currently.
I have tried to replicate the setup but I havent been able to make it work with anything other than the original chair.

@Triplelexx is it possible to use this setup in a different situation? It would be great to be able to have sitting points wherever we need them.


#5

Its ok, I managed to get it working.
I rebuilt the setup entirely and discovered it was important to set the collider box to collisionless.

This is great, it works well. as Caitlyn stated its more complicated than you might think, but totally do-able. I will try to outline what I did. I havent done any reverse engineering so I dont know whats needed and what isnt, but this workflow works…


We need 2 objects, one is the chair and the other is the collider which is an invisible box around the chair.
For my test I created 2 boxes, the red one will be the chair and I made one yellow, this will be the collider,
I just placed them next to each other for now.
First the red one I named Chair, put the following in the user data

{"allowScaling":false,"manualSitTarget":{"x":0,"y":0,"z":0},"grabbableKey":{"grabbable":false}}

then put the following in the script URL

http://mpassets.highfidelity.com/875bcd3b-7b7d-45a1-a429-c0c6eefad95d-v1/chair.js?v=1

the chair part is ready.

Now scroll back up and find the object ID: number right under the user data, copy that number including the curly braces, ctrl/c usually works.


Next the yellow box (our collider) I named Chair Collider.
Find the Parent ID: which will probably be a string of zeros, delete all that and paste the ID that you copied from the chair replacing the zeros with the chair ID, this collider now has a parent, the chair is the parent.

Now paste the following into the user data of the collider

{"grabbableKey":{"grabbable":false}}

and paste this url into the Script URL of the collider

http://mpassets.highfidelity.com/875bcd3b-7b7d-45a1-a429-c0c6eefad95d-v1/chairCollider.js?v=1

And for behaviour put a check against Collisionless

Now if I havent forgotten anything, you should be able to walk into the collider and you will be seated.
The collider can be dragged onto the chair and set invisible. You need to make sure the collider is more than half in front of the chair so you walk into the collider before you hit the chair.
When moving it, select the chair and not the collider, by clicking at the back where the chair sticks out of the collider, so the chair is selected and will drag the child collider with it as you move it.

All credit goes to @Triplelexx for writing the scripts and fixing the animations and tying it all together.


Random Picture Thread
#6

Cool, seems you have figured it all out, great job on documenting the process.
To elaborate, yes the collider must be collisionless, it is parented to the chair so it doesn’t get lost, and to allow the scripts to communicate.


#7

I did what you wrote after some other ways failed. But it’s still failing for me. and i cannot sit. Not sure what is going wrong right now.

I have my mesh chair.
And i ahve yellow entity cube. And done what you wrote.
I can stay or walk in the yellow cube. no result.

Tried a relog, stil no result.
Last try, reload content + relog to see the objects again.
Hmm, the yellow box is now invisible ! ?

Add, funny. it appeared again when i moved the collider entity. Still no luck btw.
@Triplelexx @Adrian did i mis some quirk. I know stairs not always like me anyway.

ADD: Saved the scripts to disk, so i can look at how it works and add debug lines. Not done with the chair, just started. :smiling_imp:


#8

Put the chair off the market on top of your chair move it so you’re sat in the correct place. Make the marketplace chair invisible


#9

Jasmin told me the same. not see that as solution. because copy the marketplace chair is already enough to break it. Digging in the scripts or try to rewrite things.

It seems that enterEntity = function(entityID) not get called when you enter the entity. Test version from docs page works in parent prim. I expect that enterEntity in a child prim have some problems.

ADD: Seems linked entity works fine with enterEntity. But a soon i put that script i made in the child entity of the chair. it stops working. More research needed.

ADD: localhost chaircollider with print line. enter detection work. but no sit action. The command get send to the chair script. But sit action is not triggered !


#10

@Triplelexx I get the above scripts from local disk
when i disable the section that is below this in the chair script.

`// block unacceptable attempts including the chair being tipped

if(this.isSitting || this.isStartingSit || chairRotation.x > MAX_ROT || chairRotation.x < -MAX_ROT || chairRotation.z > MAX_ROT || chairRotation.z < -MAX_ROT)
{
return;
}`


#11

Sounds like you might have missed this step


#12

No, not missed that step. because the chair Collision entity is phantom. There’s something else wrong. I first go rotate the chair in the correct direction.

Mabye found other clue. The direction of my chair where wrong. i fixt that now. and that seems very important. Because now the chair is rotated correct the script seems to work !

I changed it to this direction,

And did a rotation reset in blender.

Still think that the line that is doing the `// block unacceptable attempts including the chair being tipped protection is causing still sometimes problems.

There’s also a bug when enterEntity = function(entityID) is to close to other entity that it stop working and not detecting avatars anymore here.

ADD:

This seems the limit at this moment, i cannot adjust the vertical height. The blue cube i cannot place lower because the EntryEntity problem.

There’s no option to adjust the sit position, manualSitTarget is not doing anything.


#13

The latest version doesn’t use an entity for collision detection it uses a zone, maybe it will help with your collision detection if you try the script on the marketplace. It should also support copying.
Regarding the rotation issues. That line of code if checking that the chair is not rotated on it’s side or front/back. It is only allowed to rotate it’s yaw to be turned around.
The manual sit targeting does work, but it’s not a feature I’ve documented or advertised. If you set the coordinates to a position other than 0,0,0 it should sit you there, it’s quite difficult to use because of this, but the feature does exist.


#14

I noticed something with zone yes. i go download the new scripts and test that. Still enterEntity seems to have a problem in my eyes.

Just tried the new script after deleting lot’s of zones the script make with every reset.
It first did not worked. but you need to jump before i can sit. Looks like the zone is placed to high.

But manualsittarget is not working on the old and the new script. i did set Y = -1 But it does not change my avatar height. i change that in userdata, not documented but pretty clear. if it did work.


#15

Maybe when you’re online we should go over your offset problems in person, but the coordinates are not an offset, they must be in world space.


#16

Hmm, i do not know when you are online. It’s almost sllep time here now. World space ? how do i need to see that. yes i hope to see you inworld. If i know when.

Mabye if i understand the world coordinstes it can work. but afraid it breaks if the chair moves or other avatar ? My current sit position with the new script is the same as with the blue cube above, the script works at least now. Except the collision zone is to high i think.


#17

I am using the latest sit system on the marketplace and there is a weird issue.

Everytime I relog the collision zones seem to duplicate themselves, after setting half a dozen chairs and relogging a few times I have 30 of these zones, they are breeding like rabbits.
And if I move the chairs around the zones spawn in different places.


#18

That’s because the chair creates a new ‘detection zone’ everytime you enter the domain. I think it’s done to try to work around the inconsistancy of ‘enterEntity’.

You have to change the script to fix that.
Change this part of the chair.js script:

    makeDetectorZone: function() {
        var ent = Entities.findEntities(this.chairProperties.position, 1);		
        var StartPosition = Vec3.sum(this.chairProperties.position, Vec3.multiply(-0.25, Quat.getFront(this.chairProperties.rotation)));
        var triggerVolume = Entities.addEntity({
            type: "Zone",
	    name: "Chair detection zone",
	    position: StartPosition,
	    dimensions: {
		x: 0.65,
		y: 1.5,
		z: 0.65
	    },
	    // a registration point of 0 is enforced in y 
	    registrationPoint: {
		x: 0.5,
		y: 0.0,
		z: 0.5
	    },
	    dynamic: false,
	    parentID: this.entityId,
	    visible: false,
	    script: COLLIDER_SCRIPT_URL,
	    collisionless: true,
	    collisionsWillMove: false,
	    friction: 1.0,
	    grabbable: false,
	    damping: 0.2,
	    lifetime: -1,
	    angularDamping: 1.0,
	    shapeType: "box",
	    userData: JSON.stringify({
		grabbableKey: {
		grabbable: false
	    }
	})
    });			
		
     // END
 },

To this:

 makeDetectorZone: function() {
     // search zone, if eggsists delete an recreate
     var foundEntities = Entities.findEntities(this.chairProperties.position, 1);
     for (i = 0; i < foundEntities.length; i++) {
         var foundproperties = Entities.getEntityProperties(foundEntities[i], ["name"]);
         var n = foundproperties.name;
         if (n.search("Chair detection zone: " + this.entityId) > -1) {
             Entities.deleteEntity(foundEntities[i]);
         }
     }
 			
     var StartPosition = Vec3.sum(this.chairProperties.position, Vec3.multiply(-0.25, Quat.getFront(this.chairProperties.rotation)));
     var triggerVolume = Entities.addEntity({
 	     type: "Zone",
 	     name: "Chair detection zone: " + this.entityId,
 	     position: StartPosition,
 	     dimensions: {
 	         x: 0.65,
 		 y: 1.5,
 		 z: 0.65
 	     },
 	     // a registration point of 0 is enforced in y 
 	     registrationPoint: {
 		 x: 0.5,
 		 y: 0.0,
 		 z: 0.5
 	     },
 	    dynamic: false,
 	    parentID: this.entityId,
 	    visible: false,
 	    script: COLLIDER_SCRIPT_URL,
 	    collisionless: true,
 	    collisionsWillMove: false,
 	    friction: 1.0,
 	    grabbable: false,
 	    damping: 0.2,
 	    lifetime: -1,
 	    angularDamping: 1.0,
 	    shapeType: "box",
 	    userData: JSON.stringify({
 		grabbableKey: {
 		grabbable: false
 	    }
 	})
    });

#19

Yup, enterentity have a problem when it’s to close to other entity.

https://forums.highfidelity.com/t/script-in-entity-stops-working-seems-to-happen-when-entity-is-to-close-to-other/11572