Hi!
I wanna ask how to roll a ball.
Its not a simple roll though.
I want it to go to a full stop when I released the button
And go full speed at a press of a button
Thanks!
Hi!
I wanna ask how to roll a ball.
Its not a simple roll though.
I want it to go to a full stop when I released the button
And go full speed at a press of a button
Thanks!
Didn’t tested, but give it a try :
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.velocity = movement * speed;
}
Alfrey_Cruz8133
Hellium
if you set velocity it won’t roll it will only move you should use Rigidbody.AddForce();
code :
private Rigidbody rb;
public float speed = 10f;
void Start(){
//if script is attached on your ball
rb = GetComponent<Rigidbody>();
//if not
//rb = GameObject.Find("YourBall's Name").GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
The best solution would be to use GetComponent().AddTorque(transform.forward);
Can I have the Js version? Its very hard for me to understand C#
You could set the game object static when the button isnt pressed down.