Push and Pull Mechanism in Unity

Push and pull mechanism is one of the most general interaction in games. But how exactly the best way to apply push and pull mechanism in Unity?

So, one of my subject is Game Design, and for that subject final assignment I have to make a game in group. The lead programmer in my group assign me to do this push and pull mechanism. At first, I'm so confused and did some googling for answer. I tried to apply so many things that I found and it simply didn't work. Luckily, my lead programmer, Yodi Pramudito, is very good at Unity. He's very famous in my campus because his skill in Unity (okay, that's exaggerated LOL). So, with his Unity prowess he told me to try using joint. After that, I immediately watched unity documentation about joint and tried it... and it worked just like that.

Here's the code I used :
























So basically I just attached a new fixed joint to the push pull object and set its connected body to the character. That will produce a push pull interaction. I modified the mass to stop the object from moving if the character didn't trigger the drag interaction. Lastly, I created and destroyed new fixed joint each time the action button pushed to avoid some position bug which is occur to me before.

Any question? feel free to ask me :)

Comments

Popular Posts