Комментарии:
Im working in Godot but this is still helpful. Consider naming your videos “coyote time logic” or “jump buffering code method (example in Unity)” so you can reach a wider audience :)
Ответитьthis lines makes it possible to jump infinitely:
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
So remove it. And yeah, it is from the link on the description
I advise you to learn about coroutines
Ответитьbut you can double jump now bcs of jump buffering now if you spam jump pls help
ОтветитьIt irks me just a little that there is no underflow protection. Of course you'd need to let the game running without touching it for a ludicrously inordinate time for it to become a problem, but it would still be a good habit to handle it.
Ответитьhow do you jump
ОтветитьSuch simple and elegant implementation. I had 0 problems making it work with Love2D, thank you for help!
Ответитьanyone had the problem with if you press jump really fast the charater now can jump three time instead of two(double jump).Here is my code:
void Jump()
{
if (Input.GetButtonDown("Jump"))
{
jumpPressRemember = jumpPressRememberTime;
}
if (isGrounded || isFacingWall)
{
groundedRemember = groundedRememberTime;
}
if(jumpPressRemember > 0)
{
if (groundedRemember > 0)
{
jumpPressRemember = 0;
groundedRemember = 0;
rb.velocity = new Vector2(rb.velocity.x, jumpPower);
doubleJump = true;
dust.Play();
Debug.Log("Jump1");
}
else if (doubleJump)
{
jumpPressRemember = 0;
rb.velocity = new Vector2(rb.velocity.x, jumpPower);
doubleJump = false;
dust.Play();
Debug.Log("Jump2");
}
}
}
I don't think hollow knight have coyote time
ОтветитьThe best and easiest solution I've seen so far! 10/10
ОтветитьThank you so much ❤, you are a live-saver❤
ОтветитьPhysics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);
this 0.2f jumpBufferTime ?
Such a good tutorial! Thanks!
ОтветитьI am using the new input system and invoking my jump with unity events. I can't for the life of me figure out how to implement jump buffering in this way. Every single tutorial uses the old input system. Can someone PLEASE help!
ОтветитьIs there a way to get the jump buffer to work with the new input system? I got the coyote timer to work but I can't seem to get the jump buffer right.
Ответитьthis is amazing thanks for the simple but efficient code works amazing
ОтветитьLittle details like this are what give video games that smooth gameplay feeling.
Ответитьthanks :)
Ответитьmore mooooore we need videos like this mooooorrrrre
Ответитьty for this amazing video !
ОтветитьHey! Great tutorial! I've been trying to get this right for a week now hahaha. I got it to work, but for some reason, it only works without animation, when I add the animator to my script, it seases to work. Maybe it has somethin to do with my idle animation starting as soon as I leave the edge? If you hav any tips, I would apreciate it a lot :D
ОтветитьThanks so much for the amazing video, the camera movement for the 2d game im making is so much nicer and easier than what i was planning to do. The smooth transitions are very satisfying and im sure will be a main part of the feel of the game
ОтветитьHello, I adapted what you did in the optimized code to my own code, but I'm still experiencing the issue of the second jump being higher when executed consecutively. There could be two reasons for this. The first one is that instead of using the IsGrounded method, I directly used a bool variable. However, I don't think this is the main issue. I believe the main problem is that I used OnCollisionEnter2D instead of OverlapCircle. When I use OverlapCircle instead of OnCollision2D, the player doesn't jump at all. If you'd like to help, I can provide the code below. Thank you in advance.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Gamepad_Controller : MonoBehaviour
{
private Rigidbody2D rb2d;
private Animator animator;
public static Gamepad_Controller instance;
private float horizontal;
private float speed = 8f;
private float jumpingPower = 16f;
private bool isFacingRight = true;
private bool IsGrounded = true;
private bool isJumping;
private float cayoteTime = 0.2f;
private float cayoteTimeCounter;
private float jumpBufferTime = 0.2f;
private float jumpBufferCounter;
public int direction;
[SerializeField] GameObject trailRendererObject;
[SerializeField] bool canDash = true;
[SerializeField] bool isDashing;
[SerializeField] float dashPower;
[SerializeField] float dashTime;
[SerializeField] float dashCooldown;
[SerializeField] float dashGravity;
private float normalGravity;
private float waitTime;
private TrailRenderer tr;
private void Awake()
{
animator = GetComponent<Animator>();
instance = this;
rb2d = GetComponent<Rigidbody2D>();
normalGravity = rb2d.gravityScale;
tr = trailRendererObject.GetComponent<TrailRenderer>();
}
// Start is called before the first frame update
void Start()
{
//rb2d = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
if (isDashing)
{
return;
}
if (IsGrounded)
{
cayoteTimeCounter = cayoteTime;
}
else
{
cayoteTimeCounter -= Time.deltaTime;
}
if (!isFacingRight && horizontal > 0f)
{
Flip();
}
else if (isFacingRight && horizontal < 0f)
{
Flip();
}
}
private void FixedUpdate()
{
if (isDashing)
{
return;
}
rb2d.velocity = new Vector2(horizontal * speed, rb2d.velocity.y);
if (jumpBufferCounter > 0f && cayoteTimeCounter > 0f && !isJumping)
{
rb2d.velocity = new Vector2(rb2d.velocity.x, jumpingPower);
animator.SetTrigger("jump");
animator.SetBool("grounded", false);
IsGrounded = false;
jumpBufferCounter = 0f;
StartCoroutine(JumpCooldown());
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Zemin"))
{
IsGrounded = true;
animator.SetBool("grounded", true);
}
}
private void Flip()
{
isFacingRight = !isFacingRight;
Vector3 localScale = transform.localScale;
localScale.x *= -1f;
transform.localScale = localScale;
}
public void Move(InputAction.CallbackContext context)
{
horizontal = context.ReadValue<Vector2>().x;
if (horizontal > 0)
{
direction = 1;
}else if(horizontal < 0)
{
direction = -1;
}
animator.SetFloat("speed", speed);
if (context.canceled)
{
animator.SetFloat("speed", 0f);
}
}
public void Dash(InputAction.CallbackContext context)
{
if(context.performed && canDash)
{
StartCoroutine(Dash());
}
}
public void Jump(InputAction.CallbackContext context)
{
if (context.performed)
{
jumpBufferCounter = jumpBufferTime;
}
else
{
jumpBufferCounter -= Time.deltaTime;
}
if (context.canceled && rb2d.velocity.y > 0f)
{
rb2d.velocity = new Vector2(rb2d.velocity.x, rb2d.velocity.y * 0.5f);
cayoteTimeCounter = 0f;
}
}
IEnumerator Dash()
{
canDash = false;
isDashing = true;
float originalGravity = rb2d.gravityScale;
rb2d.gravityScale = 0;
rb2d.velocity = new Vector2(transform.localScale.x * dashPower, 0);
tr.emitting = true;
yield return new WaitForSeconds(dashTime);
tr.emitting = false;
rb2d.gravityScale = originalGravity;
isDashing = false;
yield return new WaitForSeconds(dashCooldown);
canDash = true;
}
private IEnumerator JumpCooldown()
{
isJumping = true;
yield return new WaitForSeconds(0.4f);
isJumping = false;
}
}
Just use raycast for isGrounded to get same result in better way
Ответитьthe best tutorial, seriously
ОтветитьIs it called Coyote Time because of the Roadrunner cartoon?
Ответитьbetter than chatgpt
Ответитьthis is freaking amazing. used it for the character controller brackeys made
Ответитьsuper easy and useful, thanks!
ОтветитьWhenever I press the jump button right before i land it gives my character a big Jump boost
Ответитьur a GOAT 🐐🐐🐐
Ответитьhow to fix coyote time caused double jump
ОтветитьAnyone know if there is a tutorial of this using the new input system?
ОтветитьI got a problem with this jump buffering method but i don’t know how to fix it. So ideally, when you press down on the jump button before the player reaches the ground, they would still jump and you release the button after the jump then the “rb.velocity.y * 0.5f” take into effect. The problem arises when you press and release the jump button before the player reaches the ground. The jump is already registered but because the “rb.velocity.y * 0.5f” is programmed to activate after the jump, it launches the player up with max force. I though reducing the jump buffer time would solve the problem but it only reduces the time that the issue occurs. Please help
ОтветитьHey bendux I added double jump to my game but after I added coyote time it stopped working. Why?
ОтветитьIf I spam the jump button I can sometimes jump twice. I looked at the values in coyoteTimeCounter, and sometimes instead of when I hit the jump button, coyoteTimeCounter becomes 0, it remains 0.2 and I can jump again. Do you know how to fix it? Thank you in advance
float coyoteTime = 0.2f;
float coyoteTimeCounter;
if (OnGround())
{
coyoteTimeCounter = coyoteTime;
}
else
{
coyoteTimeCounter -= Time.deltaTime;
}
if (Input.GetButtonDown("Jump") && coyoteTimeCounter > 0f)
{
rb.AddForce(jumpForce * Vector2.up, ForceMode2D.Impulse);
coyoteTimeCounter = 0f;
}
Hi I just can't figure out how I use coyote time with the new Input System and it would be really nice if someone could help me.
ОтветитьHey very helpful video, but I have a question. I am using your code, like in the description. But my character can jump multiple times while in air.
How do I solve this? I tried so many things. Pls answer in noob language :D
can understand coyote, your video do give good understanding on coyote but not the buffer jump,
ОтветитьLiked and subscribed quite fast :D pretty amazing video, and I liked the way you explained the code, thanks a lot!!
ОтветитьThank you mate, it was super easy to implement even on a multiplayer game! amazing work keep it up
ОтветитьHi. Can you do the video with Double Jump, Coyote Time and Jump Buffering. Your video is great but I can't seen to implement Coyo/Buffer to my double jump script.
ОтветитьAgain, GOLD tier tutorial and nice game design tips! Thanksss!!
Ответитьwhat I like about the tutorial is how you can implement it onto pretty much any movement script, nice tutorial
ОтветитьHey, how do i implement this is new input system? I actually tried to do this myself, but it works ... Wrong. Can you help?
ОтветитьI'm having a problem, the coyote time makes my character jump significanly lower during the coyotetime, and the timebuffer doesn't work and make the player doublejump
ОтветитьYou are amazing!!
Ответитьhow can I do this using properties ?
ОтветитьReally good tutorial, but how can i get this to work with double jumping? this seems to break my double jump
Ответить