- Home /
Creating a sonic-style charged spin
I wanted to post this in the forum as it seemed a more general query rather than an issue that needed a definite answer but I couldn't find a relevant area to post it.
I have a game where the player controls a rolling ball with a joystick. The rolling is controlled by applying force to the ball in a direction matching that of the joystick. I have a button that, when held, begins the 'spinning' action.
The spinning action is intended to pin the object in it's current position and spin him round quickly to give the impression that he's 'charging up.' Upon release of the button he launches forward with a boost.
It works, sort of.
The only problem really is that despite the function setting his velocity to 0,0,0 he still slides slightly as he spins. He slides enough to make it obvious he's not stationary anyway. This is a problem because the whole point of this mechanic is to allow for accurate dashes, effectively pausing movement, allowing the player to aim with the joystick and then dashing in the desired direction.
I think the complication comes from the joystick applying force to the ball in a direction that allows the ball to be 'pointed' whilst also applying torque to make it spin.
My question is - given the setup of my game mechanics (rigidbody.addForce driving the ball movement) is this a good way to go about this or a terrible one doomed to fail? Is there a way to make what I have work or is there a more efficient, reliable way to do it?
Thanks for reading :)
In your situation I'd be tempted to use parent and child objects for your ball. Parent handles Directional/positional movement while child would handle spin/torque. This setup would mean the ball could spin but as the direction is maintained by the parent it always overrides the direction of the ball despite which way it is facing due to spin.
With this method you can use AddTorque for the spin.
interesting idea. I will impliment and experiment with this as soon as i've figured out why my objects have stopped exploding. If it's not one thing it's another lol!
With the method I describe, the child object controls the 'animation' of the ball but not the direction of movement. You can simply align the child object to the forward direction of the parent at the end of the spin. Of course the forward direction of the parent is controlled directly by the joystick.
Ins$$anonymous$$d of freeze position you can simply zero velocity and angular velocity.
thanks for the ideas guys I'll be sure to test them both out just as soon as I can and report back with my results :)
Answer by thef1chesser · Nov 07, 2013 at 10:51 AM
Another suggestion might be to set the rigidbody constraints
when spin
sonic.rigidbody.constraints = RigidbodyConstraints.FreezePosition;
to release sonic.rigidbody.constraints = RigidbodyConstraints.None;
I got a very good result with thef1chesser's suggestion of using
rigidbody.constraints = RigidbodyConstraints.FreezePosition;
to freeze position and then the opposite to unfreeze it!
However I do see the benefit of meat5000's suggestion which I will still try when I have more time (chesser's suggestion was implemented in about a $$anonymous$$ute).
Thank you very much :)