Hi guys, completely new in unity. I’m asking how to remove double jumping. Do I have a mistake or my script is wrong? Or this code is influencing the other codes in my so that’s why it isn’t working(vice-versa)? Thanks for helping!!.
This is the part of my code that lets me jump. I also have other parts that let me move using w, a, s, d.
Please let me know if I can improve some of it and what’s the best code for that particular movement is.
If this code doesn’t have any mistakes, then it’s possible that the other parts of the script are influencing this part. Let me know if you want to check out the other parts of my script.
^— the link to the video that I watched to get most of the codes.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//Jf = Jump force
//Rb = RigidBody
public float Jf = 10f;
private Rigidbody Rb;
private bool Jumped;
void Start()
{
Rb = GetComponent<Rigidbody>();
}
void Update()
{
if (Input.GetKeyDown("space"))
{
Jumped = true;
}
}
void FixedUpdate()
{
//Jump
if (Jumped)
{
Rb.AddForce(Vector3.up * Jf, ForceMode.VelocityChange);
Jumped = false;
}
}
I really appreciate any solutions cause I've been stuck in this for a day ;-;