- Home /
Connection system like polybridge or turmoil
Currently I have a script that istantiates and stretches a game object between two mouseclicks, how can I ensure the player can spawn another one only from the loose ends of the first one? To make it simple, a system that works like oil pumps in turmoil or bridges in polybridge. The project I have in mind is not grid based but in case I can easily switch. Thank you guys in advance.
Answer by screensmith · Oct 31, 2018 at 06:53 PM
You might want to try using 2 gameObjects, one for joints (represented by a circle) and one for the bridge in between joints (represented by a line). When the player clicks on a joint then clicks elsewhere another joint is spawned and and then a bridge is spawned in between the two units. This way the player can only create bridges from other joints. You would probably connect all of the objects with a fixed joint. I haven't personally used this, but it looks like its what you want. I think it might look like this:
Player clicks on joint1
Player clicks somewhere else on screen and creates joint2 there.
You instantiate a gameobject between the two joint objects
You add a fixed joint component going from joint1 to bridge
You add a fixed joint component going from bridge to joint2
I haven't tried this myself but I think that. You would add the component with AddComponent and then edit the component's variables to set the joints.
Your answer
Follow this Question
Related Questions
Gas Fuel Implementation 0 Answers
How to find UI in code c# (button, Panel etc) 2 Answers
how to deal with GameObject class and my custom inheritance 1 Answer
How to double spirte/gameobject/prefab and control the result on those items? 0 Answers
If a script is attached to more than one gameObject, will Start() & Awake() run more than once? 2 Answers