- Home /
Velocity bug with hinge joints forces in C#
Hi,
At a local game jam I made a game with a friend in Unity called Suction Co-Op. It's a two-player game where each control the end of a dual suction cup. Read more about the game here: http://gustavdahl.net/suction-co-op.
It works quite well via hinge joints motors. However, there is a bug where they won't reset their velocity, but instead keeps adding more and more speed.
It is hard to explain, so I suggest you play it yourself right here: http://gustavdahl.net/Unity_games/SuctionCoOp/WebPlayer.html
I am having difficulties about isolating the bug; I'm not sure how and when it happens, but when you experience it yourself it is very easy to see (you keep spinning around very fast!).
One way to reproduce the bug is doing the following when the game plays: Press and hold D and Left Arrow at the same time, while you repeatedly taps the S and Down Arrow. This will make the cups keep on adding force without reseting it.
As you can probably see, it makes the game very hard because of the high speed. We would love to eliminate the bug.
We are all novice programmers, and this game was made in under 48 hours, hence the crappy slam code. I would really appreciate if anybody would look at it and see if they can catch the bug.
Thanks in advance!
The game uses States and simple keyboard input to make the players move. The script (written in C#) is attached to a cylinder where each end is attached through a hinge joint to an empty gameobject (hence making it stick to the wall).
I know this is a long one, but since I am not sure where the bug precisely is, I have to copy-paste this long snippet (it is not the whole code): http://pastebin.com/ZfMkXrvv