going_balls/Assets/Scripts/BallController.cs

24 lines
679 B
C#

using UnityEngine;
public class BallController : MonoBehaviour
{
float maxSpeed = 10f;
public Rigidbody Rb;
public float Speed;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void FixedUpdate()
{
float x = Input.GetAxis("Horizontal");
float y = Input.GetAxis("Vertical");
Rb.AddTorque(Vector3.right * x * Speed, ForceMode.Acceleration);
Rb.AddTorque(Vector3.forward * y * Speed,ForceMode.Acceleration);
Rb.angularVelocity = Vector3.ClampMagnitude(Rb.angularVelocity, maxSpeed);
}
}