if someone would be kind enough to post the corect script for the roll a ball tutorial because the one that is given in the tutorial dosnt seem to work
@Zitoox I don’t want to drag the player I want to use certain keys to move it but it doesn’t clarify which keys it’s supposed to use and the ball is already named player
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : MonoBehaviour {
public float speed = 5.0f;
private Rigidbody body;
void Start () {
body = GetComponent<Rigidbody>();
}
void FixedUpdate (){
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
body.AddForce (movement * speed);
}
}
//or
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : MonoBehaviour {
public float speed = 5.0f;
private Rigidbody body;
void Start () {
body = GetComponent<Rigidbody>();
}
void FixedUpdate () {
float moveHorizontal = 0;
float moveVertical = 0;
if(Input.GetButtonDown(KeyCode.A)) // if keybutton down
moveHorizontal = -1;
else if(Input.GetButtonDown(KeyCode.D)) // if keybutton down
moveHorizontal = 1;
if(Input.GetButtonDown(KeyCode.S)) // if keybutton down
moveVertical = -1;
else if(Input.GetButtonDown(KeyCode.W)) // if keybutton down
moveVertical = 1;
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
body.AddForce (movement * speed);
}
}
Hope this helps you out a bit