Hi I have made a little ball controller script, but it won’t work as I wish it would.
My ball is suposed to roll when I use the directional keys, but I only want it to roll when the ball isnt rolling faster than my buttons can make it.
Can someone tell me how to solve this?
Here is my code:
using UnityEngine;
using System.Collections;
public class BallController : MonoBehaviour {
public float ballSpeed;
void Update()
{
float xSpeed = Input.GetAxis("Horizontal");
float ySpeed = Input.GetAxis("Vertical");
Rigidbody body = GetComponent<Rigidbody> ();
if(body.angularVelocity.x >= body.angularVelocity.x * ballSpeed * Time.deltaTime)
{
body.AddTorque(new Vector3(xSpeed, body.angularVelocity.z, body.angularVelocity.y) * ballSpeed * Time.deltaTime);
}
if (body.angularVelocity.y >= body.angularVelocity.y * ballSpeed * Time.deltaTime)
{
body.AddTorque(new Vector3(body.angularVelocity.x, body.angularVelocity.z, ySpeed) * ballSpeed * Time.deltaTime);
}
}
}