Swinging gate or door

153 views
Skip to first unread message

tom.w...@gmail.com

unread,
Oct 4, 2017, 9:17:38 PM10/4/17
to CoSpaces
I'm creating a petting zoo space. I would like a swinging gate.
I have three wall segments end-to-end. The two on the outside are longer and are the "fence". The third segment, the "gate", is shorter and between the other two segments.

All the code I've tried swings the gate from it's center. That make the gate look like it's spinning. I want to swing the gate from one side. Like it's on hinges attached to the longer wall.

Suggestions welcome, thanks!

Benjamin Singh

unread,
Oct 5, 2017, 3:38:06 AM10/5/17
to CoSpaces
Hi Tom,

can you please share the space with us so we can have a better look at your example?

Just click on the share button in the scene...


...and share the direct link with us.


Thanks,

Benjamin



tom.w...@gmail.com

unread,
Oct 5, 2017, 5:55:30 AM10/5/17
to CoSpaces

Benjamin Singh

unread,
Oct 5, 2017, 7:36:19 AM10/5/17
to CoSpaces
Ok thanks. I changed the code a bit.


1. I moved the "on activate of" block to the top of the script. Otherwise the event listener will be set after the other code is being executed.

2. Also, I changed the vector properties. The vector points straight up in 3D space now (x = 0, y = 0, z = 1) and there is a small offset (x = 0.3) regarding the origin point of the vector. So that the rotation axis will be shift to the end of the gate rather than being in the center of it.


Now it should work like expected.


Benjamin



tom.w...@gmail.com

unread,
Oct 5, 2017, 1:59:26 PM10/5/17
to CoSpaces
Awesome!
I added a variable so the code knows if the gate is open or close.
Now the gate will close instead of continuously swinging in the same direction.



What do you think of the flashing marquee?
I'd like to finish it and save it as an object so I can use it other scenes.

Thanks for the help!

-Tom

Benjamin Singh

unread,
Oct 6, 2017, 4:29:33 AM10/6/17
to CoSpaces
Hi Tom,

glad that it worked! Yes, definitely good idea to implement a open/closed state. The flashing lights are also very cool!

I wanted to mention that there is maybe a better way to implement a swinging door in CoSpaces using Blockly. You can use a hinge and the main part of the door, attach them, rearrange the main part so it fits nicely and then use Blockly to just rotate the hinge.

1. Create hinge and main part.


2. Attach main part to the hinge.





3. Rearrange the main part by dragging it to the right place.



4. Some Blockly.


Result:



In this case it definitely makes more sense doing it that way and it's more logical instead of using the "turn" block using vectors which can be confusing. Also, using the attach feature you can implement complex mechanisms just using simple Blockly.


Benjamin


tom.w...@gmail.com

unread,
Oct 6, 2017, 10:20:21 PM10/6/17
to CoSpaces
Many Thanks.

Great lesson. You can bet I'll use the hinge; gates, trap doors, draw bridges, custom doors and windows. Can you see multiple hinges and panels be used to create an undulating surface like a waterfall? Logic gates? A lifting device a'la Archimedes screw?
I didn't know attachment points could be moved. That will ease assemby of complex models.

-Tom

tom.w...@gmail.com

unread,
Oct 7, 2017, 1:00:36 AM10/7/17
to CoSpaces

I made an improvement to the code. In your code if you kept clicking the gate it would keep swinging beyond the 90 degrees.
I added a variable, isSwinging. If the gate is not already swinging, the gate is put in motion. If the gate is already swinging, clicks are ignored until the swinging is stopped.


Benjamin Singh

unread,
Oct 9, 2017, 6:08:46 AM10/9/17
to CoSpaces
Hi Tom,

very cool! Yes, with the attach feature using multiple hinges you can do very complex structures and program them using Blockly. Especially when you combine it with the physics functions provided.

Benjamin
Reply all
Reply to author
Forward
0 new messages