So, i am very new to unity and just started my new game today. Everything is right, except from jumping. I can jump infinitely in mid-air and i dont want that.
Tha script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public CharacterController2D controller;
public float runSpeed = 40f;
float horizontalMove = 0f;
bool jump = false;
// Update is called once per frame
void Update()
{
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
if (Input.GetButtonDown("Jump"))
{
jump = true;
}
}
void FixedUpdate ()
{
controller.Move(horizontalMove * Time.fixedDeltaTime, false, jump);
jump = false;
}
}
Hi @Illuminati23 ,
You don’t have any rule in your jump button press - You do record the information that you are jumping, but you don’t test for it anywhere. So, why not test like this:
if (Input.GetButtonDown("Jump") && jump != true)
Then, only when your character lands / dies (or whatever cases you might have) you reset the jump value.
I did, I watched the “player movement 2d tutorial” by brackeys. I wish I could change my code but when I go to other videos the whole script is different.