I’m pretty new to Unity and coding, and what I’m trying to do is make an ‘expanded version’ of the small Roll-A-Ball tutorial game in the Unity Tutorials.
I’m currently trying to make a simple jump function, that moves the ball (The player) up, or along the Y axis. I have made some code which will move the ball, but for some weird reason, it moves the ball along the X axis instead, which is sideways along the floor. This is my C# code:
public class Jumper: MonoBehaviour
{
public float speed;
void Start ()
{
}
void FixedUpdate ()
{
float moveJump = Input.GetAxis("Jump");
Vector2 movement = new Vector2(moveJump, 0.0f);
GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
}
}
I’m using code similar to the perfectly functional one I have which moves the ball normally on the floor, which if you need to know is:
public class PlayerController : MonoBehaviour
{
public float speed;
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
}
}
From what I can tell the code is fine, but for some reason ‘MoveJump’ decides the move along X, instead of the Y axis. Is there a way to change which Axis ‘MoveJump’ uses? Or do I have to do something completely different instead?