How do I make a ball roll in 3D?
This is my script. #pragma strict
var vetrotationSpeed = 100; var hotrotationSpeed = 100; var jumpHeight = 8;
private var isFalling = false;
function Update () { //Handle ball moving var horrotation : float = Input.GetAxis("Vertical") hotrotationSpeed; var verrotation : float = Input.GetAxis("Horizontal") vetrotationSpeed; horrotation = Time.deltaTime; GetComponent.().AddRelativeTorque (Vector3.back horrotation); verrotation = Time.deltaTime; GetComponent.().AddRelativeTorque (Vector3.left verrotation);
if (Input.GetKeyDown (KeyCode.Space) && isFalling == false) { GetComponent.().velocity.y = jumpHeight; } isFalling = true; }
function OnCollisionStay () { isFalling = false; }
I am having a problem where once I move my ball on the x axis it won't let me move it on the z axis. maybe if the ball had a fixed rotational spot. please help thanks.
Answer by adrienPlayerium · Aug 24, 2017 at 04:10 AM
Not sure but this should be able to help you https://unity3d.com/fr/learn/tutorials/projects/roll-ball-tutorial