So, this should be a very basic thing to do, all of the other key inputs in this script works, but for some reason, this key input does not. Anyone know why
using System.Collections; /*We are using the "using" keyword to signify that we are implementing the Collections class of the System package(because
unity can not use Generic as a baselayer for a script) in this scope/file*/
using System.Collections.Generic; /*We are using the "using" keyword to signify that we are implementing the Generic class of the System.Collections
package(because it contains generic class definition and provides you to better type safly) in this scope/file*/
using UnityEngine; /*We are using the "using" keyword to signify that we are implementing the UnityEngine class(because it allows us to use all of
unity class definitions, keywords, default method and everythine) in this scope/file*/
public class PlayerMovementE5 : MonoBehaviour /*Creates a public(which means it's accesible to every other file) with the name
"PlayerMovementE5" that imports it with the baseclass of "MonoBehaviour"(which means it can be attached to a gameobjct)*/
{
public Rigidbody rb; /*Creates a public(which means it can be accesed by either the inspectoor-if thsscript is attached to a object-or to
another script if that script imprts this file) using the Rigidbody keyword(which is a component that can be attached to a gameobject)
nicknamed "rb"*/
public Vector3 jump;
public float moveForward = 200f; /*Creates a public(meaning it can be changed via the inspector and called in other scripts) float(meaning it can have de
cimals) nicknamed "moveForward" that has a value of 200*/
public float moveBackward = -200f;/*Creates a public(meaning it can be changed via the inspector and called in other scripts) float(meaning it can have de
cimals) nicknamed "moveBakward" that has a value of -200*/
public float moveLeft = -150f;/*Creates a public(meaning it can be changed via the inspector and called in other scripts) float(meaning it can have de
cimals) nicknamed "moveLeft" that has a value of -150*/
public float moveRight = 150f; /*Creates a public(meaning it can be changed via the inspector and called in other scripts) float(meaning it can have de
cimals) nicknamed "moveRight" that has a value of 150*/
public float moveUp = 1.0f;
public float maxSpeed = 20f;
public float minSpeed = 0f;
public float currentForwardSpeed;
public float currentBackwardSpeed;
public float currentLeftSpeed;
public float currentRightSpeed;
public bool isGrouded;
void Start() /*Creates a void(Which means it returns nothing) constructor nicknamed with the pre-made Unity Consstructor "Start" and...*/
{
//rb.useGravity = false; /*Sets the useGravity on the nicknamed rididdbody 'rb' to false(meaning the gameobject has no gravity)*/
Debug.Log("I'm floating!! Wheee"); /*Logs a message to the console thatsays whatevers in the paranthesis*/
jump = new Vector3(0.0f, 1.0f, 0.0f);
}
void OnCollisionStay() {
isGrouded = true;
}
// Update is called once per frame
void Update() /*Creates a void(Which means it returns nothing) constructor nicknamed with the pre-made Unity Consstructor "Update" and...*/
{
if(Input.GetKeyDown(KeyCode.Space) && isGrouded) {
rb.AddForce(jump * moveUp, ForceMode.Impulse);
isGrouded = false;
}
}
void FixedUpdate() { /*Creates a void(Which means it returns nothing) constructor nicknamed with the pre-made Unity Consstructor "FixedUpdate",
and...*/
currentForwardSpeed = moveForward * Time.deltaTime; /*Make the nicknamed float "currentForwardSpeed" equal to the icknamed float
"moveForward" multiplied by Time.deltaTime)*/
currentForwardSpeed = Mathf.Clamp(moveForward, minSpeed, maxSpeed);
rb.velocity = new Vector3(rb.velocity.x, rb.velocity.y, (currentForwardSpeed));
if(Input.GetKey("s")) { /*Passes the "s" button as an arguement in the GetKey method of the Input class as the if condition(meaning if s
gets pressed) and...*/
currentBackwardSpeed = moveBackward * Time.deltaTime;
currentBackwardSpeed = Mathf.Clamp(moveBackward, minSpeed, maxSpeed);
rb.velocity = new Vector3(rb.velocity.x, rb.velocity.y, (currentBackwardSpeed));
}
if(Input.GetKey("d")) { /*Passes the "d" button as an arguement in the GetKey method of the Input class as the if condition(meaning if d
gets pressed) and...*/
currentRightSpeed = moveRight * Time.deltaTime;
currentRightSpeed = Mathf.Clamp(moveRight, minSpeed, maxSpeed);
rb.velocity = new Vector3((currentRightSpeed), rb.velocity.y, rb.velocity.z);
}
if(Input.GetKey("a")) { /*Passes the "s" button as an arguement in the GetKey method of the Input class as the if condition(meaning if s
gets pressed) and...*/
currentLeftSpeed = moveLeft * Time.deltaTime;
currentLeftSpeed = Mathf.Clamp(moveLeft, minSpeed, maxSpeed);
rb.velocity = new Vector3((currentLeftSpeed), rb.velocity.y, rb.velocity.z);
}
if(rb.position.y < -250f) { /*Gets the variable nicknamed "rb" and get the y value and see if its has a y value of less than -100 then...*/
FindObjectOfType<GameManagerE5>().EndGame(); /*Findthe game object "GameManagerE5" and uses it's method "EndGame""*/
}
}
}
and if you’re wondering why I’m not useing rb.AddForce() is because rb.AddForce() gradually speeds up the player throughout the game and I want the speed to remain constant
*EDIT: I just relized I did not say what key input isnt working, its a