So I need a scrpt where my player can jump-pretty simple, right? Well, I cant seem to figure it to make it compatible with what else I got in the script.
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;
Vector3 movement;
public float minSpeed;
public float maxSpeed;
public float InputSpeed;
public float AutomaticSpeed;
public float JumpSpeed;
float goFowards;
public bool isGrounded;
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, 2.0f, 0.0f);
}
void OnCollisionStay() {
isGrounded = 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) && isGrounded) {
rb.AddForce(JumpSpeed * jump, ForceMode.Impulse);
isGrounded = false;
}
float moveHorizontal = Input.GetAxisRaw("Horizontal");
float moveVertical = Input.GetAxisRaw("Vertical");
movement = new Vector3(moveHorizontal, 0, moveVertical);
movement = movement * InputSpeed * Time.deltaTime;
}
public void FixedUpdate() { /*Creates a void(Which means it returns nothing) constructor nicknamed with the pre-made Unity Consstructor "FixedUpdate",
and...*/
rb.velocity = movement;//new Vector3(rb.velocity.x, rb.velocity.y, (Speed));
//rb.velocity = new Vector3((Speed), rb.velocity.y, rb.velocity.z);
goFowards = AutomaticSpeed * Time.deltaTime;
goFowards = Mathf.Clamp(AutomaticSpeed, minSpeed, maxSpeed);
rb.velocity = new Vector3(rb.velocity.x, rb.velocity.y, (goFowards));
}
}
I have tried putting rb.velocity = new Vector3 in the if statement and movement = 0, JumpSpeed, 0 in the if statement