- Home /
How to make ball softly stop! Basic scripting
So i have a ball that rolls but it suddenly stops when i let go of the keys, i want it stop but stop softly with a bit of extra roll not just a sudden stop. How can i achieve this?
this is my ballcontroll script
public class Ballcontroller2 : MonoBehaviour {
public float movespeed;
private Rigidbody myrigidbody;
private Vector3 moveInput;
private Vector3 moveVelocity;
// Use this for initialization
void Start () {
myrigidbody = GetComponent<Rigidbody> ();
}
void Update () {
moveInput = new Vector3 (Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
moveVelocity = moveInput.normalized * movespeed;
}
void FixedUpdate () {
myrigidbody.velocity = moveVelocity;
}
}
Thanks in advance! --byrd :)
Ins$$anonymous$$d of using myrigidbody.velocity, check out the AddForce method.
Also take a look at your rigid body in the inspector and make sure your drag and angular drag values are appropriately low.
Another thing to look into is using physics materials. You can set their friction and bounce components as well as how they interact with other physics materials' bounce and friction components.
Hey thanks for the reply and i did check out the add force method and it did the trick! thanks for your help! Really appreciate you replying. -byrd
Additionally, you might want to take a look at Rigidbody.maxAngularVelocity -- Increasing this will let the ball roll much faster, rather than sliding along the ground.
Answer by eskivor · Jun 14, 2017 at 04:13 PM
Try to tweak the physic material of your ball and your floor (especially the friction parameter), it could help you.
Your answer
![](https://koobas.hobune.stream/wayback/20220612124112im_/https://answers.unity.com/themes/thub/images/avi.jpg)