Question by
elvish_unity · Jun 01, 2019 at 04:28 PM ·
c#unity 5double jump
Double Jump Unity
My script for double jumping is not working I have tried changing the conditions and values but it never seems to work. When I jump it does not + 1 but it +2
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ControllerScript : MonoBehaviour
{
public float speed;
public float jumpVelocity;
public float fallMultiplier = 2.5f;
public int currentJump = 0;
bool isGrounded = true;
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if(isGrounded == true)
{
currentJump = 1;
}
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxisRaw("Horizontal");
float moveVertical = Input.GetAxisRaw("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
movement = Vector3.ClampMagnitude(movement, 1);
rb.AddForce(movement * speed * Time.deltaTime);
if (Input.GetKey(KeyCode.Space) && (isGrounded || currentJump < 3))
{
GetComponent<Rigidbody>().velocity = Vector3.up * jumpVelocity;
currentJump++;
}
if (rb.velocity.y < 0)
{
rb.velocity += Vector3.up * Physics.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
}
}
void OnCollisionEnter(Collision collision)
{
Debug.Log("Entered");
if (collision.gameObject.CompareTag("Platform"))
{
isGrounded = true;
}
}
void OnCollisionExit(Collision collision)
{
Debug.Log("Exited");
if (collision.gameObject.CompareTag("Platform"))
{
isGrounded = false;
}
}
}
Comment
Answer by Pgup1 · Jul 26, 2019 at 10:41 AM
The best way to make double jump: https://www.youtube.com/watch?v=Xv5to65kd4E&t=2s
Your answer
Follow this Question
Related Questions
Black Scrreen after Splash Screen after deploy on HoloLens 1 Answer
Loot table problems 1 Answer
Game crashes on iPhone 11 0 Answers
Need help with Mute Button 1 Answer