Not liking the spring joint

Unity Mobile Course
Ball Launcher, lesson 8, “Launching The Ball”

I’m overall liking this course so far and this project. There’s some mobile-specific lessons coming up that look just awesome. I get that the meat of the course is on the mobile-specific stuff and not teachning the best ways of making 2D games.

But… I don’t think the spring joint should be used for this game. Much of our code and design effort is spent fighting the spring joint. Instead, it seems like we should just have the ball at the anchor point, but not attached, and left as kinematic so it hovers there.

When we drag the ball away and then launch, we should just set the velocity of that ball at that point so that it goes sailing toward the anchor. Something like this should do:

currentBallRigidbody.isKinematic = false;

currentBallRigidbody.velocity = (anchor.transform.position - currentBallRigidbody.position) * launchForce;

It will still need a little trial and error to figure out the launchForce you like for your game, but it will be to get the speed you want not to try to get it working at all. And there will be zero chance of the ball pingponging around instead of launching.

I was excited to learn about using the spring joint. I’d like get more practice with it. But we’re using it in almost opposite to how joints are supposed to work, trying through trial and error to disable it so it doesn’t ruin our game. It’s a square peg in a round hole, just to save us one line of code.

So if you are interested, I present my own challenge… to refactor this project so it doesn’t use a spring joint at all and instead gives you control over how far you need to pull the ball back to get the desired speed.


Privacy & Terms