- Home /
Spring Joint and Tethered Ball
Hello,
I am wondering what the best approach for handling a tethered ball on a moving player might be. This is for 2D endless runner game. I have a CharacterController that runs right and increases velocity constantly.
Underneath the player transform I have a rigidBody(set to kinematic). The player holds a ball sprite which also has a rigid body and a configurable joint that operates like a spring joint. Have tried with a spring as well. The rigidBody under the player is the connected body. I have all of my settings set so that when the User mouse clicks a point then I apply a force and the ball sprite / sphere collider / rigid body goes flying off in x and y and then springs back.
I run into problems when the velocity of the player increases. The ball motion and trail renderer attached to it begin to stutter . That makes sense though since the player is moving faster.
I'm just wondering if this is the cleanest approach to something like this. It works OK I guess but I feel like I could do it better. I could try using non physics but would have to handle the collisions and get into some Vector math which I could do but would mean a lot of re-writing.
Also wondering if this is not a bad way to go then how should I set up my joint. I've looked in a few places and its hard to get any good reference on Configurable joints. Spring joint works about the same.
Thanks
to be clear, it is a CharacterController ?
could you post an image showing the general situation so it's clearer, the sizes involved etc.
One thing you may have to do: "mixed" rigs are tricky. You may have to do something like this: make an invisible new physical object we'll call "the blimp". Write some code for it, using "AddForce" etc, that keeps the blimp always following the Character as best as it can. (Not unlike say a "camera car".) So it's a totally independent object, there is no parent relationship.
then, connect a "chain" perhaps with a "ball" on the end, actually to the "virtual blimp". (I'm not clear if you mean the ball is "on a string" or it just sort of bounces along with the player)
some thoughts...
Thank you for the reply. Yes it is a character controller. The camera is orthographic and the size is set to 10. I'm using Sprite$$anonymous$$anager2 with pixel perfect on so my player sprite is about 90pixels tall.
The controller is on that gameObject. The connected body / rigid body is parented under the player sprite. I totally understand what you are saying about the independent "virtual blimp" .. I will give that a try. Would you know where the best place to place my configurable joint anchor at?
I've attached an image so that you can see what is going on. The player is moving in positive x and the ball's transform is placed exactly where the connected body is (slightly offset in positive x from the controller so that when the user presses the mouse button and launches the ball it does not collide with the character controller)
The ball is set to the connected body's position in the Update function as kinematic until someone launches it.
everything seems to work but I know there has to be a cleaner way. Thanks again!
Again
Connected body which you cant see in the image is parented under the sprite/character controller. I switch kinematic off and on on the ball spite ( just a sphere collider and rigid body) when the user launches the ball.
Your answer
Follow this Question
Related Questions
Two way joint? 1 Answer
Getting a configurable joint to point at another object 2 Answers
Joint: Swing & Twist? 1 Answer
Configurable joints rotating at a certain angle 2 Answers
Is there a way to rotate the anchor of configurable joint? 0 Answers