Recently I’ve been trying to create a script to move the player from left and right. I’ve assigned everything in the editor, and added a considerable amount of force, but when I play and press the keys the player is not moving. I’ve asked several other people, and no one has been able to help me. Why is this not working?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public Rigidbody rb;
public float MoveSpeed;
public float JumpSpeed = 9999f;
public bool JumpCheck;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
JumpCheck = GetComponent<CheckIfJump>();
}
// Update is called once per frame
void FixedUpdate()
{
if (Input.GetKey(KeyCode.RightArrow))
{
rb.AddForce(Vector3.right * JumpSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.LeftArrow))
{
rb.AddForce(Vector3.left * JumpSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.Z) && JumpCheck == true)
{
rb.AddForce(transform.up * JumpSpeed * Time.deltaTime);
}
Debug.Log(rb.velocity);
}
}