Hey there!
I’m making a very simple game where a sphere jumps when I press “space” and the arrow keys move the sphere left and right.
However, when I press the left arrow key the player goes right and vice
How do I get the arrow keys to function as they should?
I think its a Camera error- but I’ll place my coding for the player in just in case.
here is my code for my player- the sphere;
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
private Rigidbody rb;
public float speed;
public float jumpSpeed;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown("space"))
{
print ("key pressed");
MakeMeJump();
}
}
void MakeMeJump()
{
rb.AddForce (Vector3.up * jumpSpeed, ForceMode.Force);
}
// Update is called once per frame
void FixedUpdate () {
float horizontalMovement = Input.GetAxis("Horizontal");
float verticalMovement = Input.GetAxis("Vertical");
Vector3 movement = new Vector3 (horizontalMovement, 0.0f, verticalMovement);
rb.AddForce (movement * speed);
Debug.Log (horizontalMovement);
Debug.Log (verticalMovement);
}
}