Hi. I am working on a demo scene for the door presentation. I set up door interaction, however I have a problem with using
translateLocal() method. When I open the door for the first time, a door mechanism appears. If I close the door and open it again, the mechanism no longer appears. However, if you display the coordinates of this mechanism in the console, then you can see that the movement occurs. I will be glad to any help or tips.
Link to the project: https://playcanvas.com/editor/scene/722406
Did a quick test to check on translateLocal and it seems to work fine (press space to move the box up).
This suggests that there is a problem with the surrounding code and not translateLocal itself.
Then there a problem in my code, but I cannot understand exactly where.
The logic of DoorComponent.js looks right to me. But then, I’m new to this and it doesn’t work. So I’m probably wrong. But what you do know is that the bolts come out and go back as planned. But do they really move back to the 7.8 position and stay there as you think? What I would probably do is to change the door material to be partially transparent so that I could visually observe what the bolts are doing. If they are in the right position, then I’d put console statements into key positions to determine if the states I’m testing for are actually what I think they are.
Given that the bolts do go out and then back in you are clearly using translateLocal correctly. The problem must be elsewhere.
Line 125 shoud be this:
this.doorBoltEntity.setLocalPosition(7.8, 2.72, -0.5);
You need to set all three values. When you only set one, setLocalPosition put your bolts in the wrong place. I’m guessing at 7.8 for all three coordinates. But you can test that yourself if you want.
I forked your project and dissolved the door out and saw that the bolts instantly disappeared after they moved back. So what happens at that point? setLocalPosition. Now that I’m looking at one thing I could see the problem that I should have noticed earlier.
BTW, that’s a lot of bolts for a door. Also, hinges on the outside are not very secure in the real world. So if the idea is to suggest robust security, then maybe they should be on the inside?
Thank you very much for your help, the problem really turned out to be that it was necessary to additionally transmit the coordinates y and z. Apparently I lost a little tired, since I was doing this project in just 1 day. I forgot that before that I had a similar problem with the
setLocalEulerAngles() method, which also worked incorrectly with one coordinate x.
I made this door according to the drawings that the door manufacturer gave me, so I think that security is all right.