- Home /
How to roll the ball?
How to roll ball? I need rolling with correctly rotation!
Actually I want to get metall ball. $$anonymous$$aybe I need use some physics material?
use rigidbody.AddForceAtPosition and move the force up a bit, that should help. P.S. Why cannot I add comment to my own answer
I need corectly rotation - try to make rigidbody ball , just with addforceatpos or addforce, you will see that ball just slide!
It works just fine for me, try this script: using UnityEngine; using System.Collections;
public class Force : $$anonymous$$onoBehaviour {
// Use this for initialization
void Start () {
rigidbody.SetDensity(900);
}
// Update is called once per frame
void Update () {
rigidbody.AddForceAtPosition(new Vector3(10, 0, 0)/*THIS IS THE FORCE!*/, new Vector3(transform.position.x, transform.position.y + 0.2f, transform.position.z));
}
}
Answer by raoz · Mar 26, 2012 at 04:31 PM
Use rigidbody, it is physics simulation, it has sphere, more information - http://unity3d.com/support/documentation/Components/class-Rigidbody.html
I use rigidbody! But ball has not-correctly rotation. I use AddForce to move ball, but rotation is NOT-CORRECTLY!
to push the ball around but to only have it rotate in the Y axis , you need to set the properties of the rigidbody.
In the Inspector , under the Rigidbody Component , scroll down and find the last property : Constraints
For what you want , under Freeze Rotation , Tick the X and Z checkbox. This will then stop the ball rolling forward or sideways, it will only turn to the left and right.
You need to leave the Y Unticked if you want to turn the gameObject to face a direction.
The link provided by @raoz has all this information : scroll down to Constraints.
http://unity3d.com/support/documentation/Components/class-Rigidbody.html
Your answer
Follow this Question
Related Questions
Ball Z-Axis Rolling 1 Answer
Create a "free" rolling ball controlled by player 1 Answer
How to make a ball that can roll? 2 Answers
iPhone ball roll problem 2 Answers