Roll a Ball game. Ball Rolling Diagonally
Hey, I'm clearly a newbie to this whole Unity thing including Coding. I got my hands on the basic Ball Rolling game Tutorial, Allready encountered a little problem. In the code I'm in the point of Applying force to a Body with physics, a Ball in this case. Here's the code
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Horizontal");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement);
}
}
So I'm pretty damn sure this code is correct, Cause the force is indeed applied, but it's the WAY it's applied that's the problem. I am not sure if this is a common issue for new coders but the Ball's moving Diagonaly, When presing left it reacts like Pressing Left AND down same thing opposite side instead of down it's going Upwards. IF it is a code issue, I'll be more than glad to be educated :D
I think you made a copy/paste error here.
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Horizontal");
You are getting the "Horizontal" axis for both moveHorizontal and moveVertical. It should work if you replace Horizontal with Vertical in
float moveVertical = Input.GetAxis("Horizontal");