- Home /
Create a "free" rolling ball controlled by player
So I asked this question a couple weeks ago but I didn't get a response that worked. What I'm trying to figure out is how I can make a cube controlled by a player roll freely. Not just a rolling animation, but more of a roll due to physics. So I wouldn't need to make around 30 animations just for it to roll. Here is an example of what I would like to figure out how to do: http://www.youtube.com/watch?v=yuyiItRJ6EE (Marble blast ultra) just the rolling mechanism in it. Help on this would be greatly appreciated. Things I have already tried (May have missed some):
Adding a Rigidbody to the sphere
Using animations on the sphere.
And yes, I have tried adding a texture so I know it's not rolling =(
Thanks ahead of time - Valestrom
I don't mean to get you down, but this question has been asked many, many times, and successfully answered almost every time. The search function would probably have worked wonders. But as Bunny says, AddTorque is essential, as well as an understanding of Physics $$anonymous$$aterials so that you can apply enough friction to make rolling viable.
Answer by Bunny83 · Jul 06, 2011 at 03:51 AM
Rigidbody.AddTorque (esp. this one)
So now it rolls, thanks! All I should have to do now is make a character controller that adds force and torque?
I hope you can help with this, I have this as my code:
function FixedUpdate () { if (Input.GetButton("W")) { rigidbody.AddTorque (Vector3.forward 2); rigidbody.AddForce (Vector3.forward 2); } } function FixedUpdate () { if (Input.GetButton("S")) {
rigidbody.AddTorque (Vector3.-forward 2); rigidbody.AddForce (Vector3.-forward 2); } function FixedUpdate () { if (Input.GetButton("A")) { rigidbody.AddTorque (Vector3.left 2); rigidbody.AddForce (Vector3.left 2); } } function FixedUpdate () { if (Input.GetButton("D")) { rigidbody.AddTorque (Vector3.right 2); rigidbody.AddForce (Vector3.right 2); } }
But I get these errors
(Filename: Assets/$$anonymous$$ovementscript.js Line: 6)
Assets/$$anonymous$$ovementscript.js(12,29): BCE0044: expecting ), found '.'.
(Filename: Assets/$$anonymous$$ovementscript.js Line: 12)
Assets/$$anonymous$$ovementscript.js(12,42): BCE0043: Unexpected token: ).
(Filename: Assets/$$anonymous$$ovementscript.js Line: 12)
Assets/$$anonymous$$ovementscript.js(13,28): BCE0044: expecting ), found '.'.
(Filename: Assets/$$anonymous$$ovementscript.js Line: 13)
Assets/$$anonymous$$ovementscript.js(13,41): BCE0043: Unexpected token: ).
(Filename: Assets/$$anonymous$$ovementscript.js Line: 13)
Assets/$$anonymous$$ovementscript.js(19,38): UCE0001: ';' expected. Insert a semicolon at the end.
(Filename: Assets/$$anonymous$$ovementscript.js Line: 19)
Error: Analytics Event: 5(Compiler*UCE0001*';' expected. Insert a semicolon at the end.)(1): skipped because it was sent more than once in 0.10 seconds Assets/$$anonymous$$ovementscript.js(26,39): UCE0001: ';' expected. Insert a semicolon at the end.
(Filename: Assets/$$anonymous$$ovementscript.js Line: 26)