Variable jump height not working in godot 4 c#

Godot Version

Godot 4.2.1 stable-mono win64

Question

I am very new to godot, and one of the first things I am trying to do is make a simple 2D platformer. I am using C#, as I am already familiar with Unity, and my script is acting kind of strange. My intention is to have a character that can be moved left and right, a jump with coyote time and a jump buffer, and variable jump height, but the variable jump height isnt working. Here is my script, which is attached to a CharacterBody2D, which is the parent of a sprite2D and CollisionShape2D:

using Godot;
using System;
public partial class Player : CharacterBody2D
{

	public bool CanWallJump;
	public float movementSpeed = 150f;
	public float jumpVelocity = 200f;
	public float CoyoteTime = 0.4f;
	public float CoyoteCount;
	public float Buffer = 0.2f;
	public float BufferCount;
	public float gravity = ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();
	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
	}

	// Called every frame. 'delta' is the elapsed time since the previous frame.
	public override void _PhysicsProcess(double delta)
	{
		Vector2 velocity = Velocity;
		if(IsOnFloor() == false)
		{
			velocity.Y +=  gravity * (float)delta;
		}
		if(IsOnFloor())
		{
			CoyoteCount = CoyoteTime;
		}else{
			CoyoteCount -= (float)delta;
		}
		if(Input.IsActionJustPressed("Jump"))
		{
			BufferCount = Buffer;
		}else{
			BufferCount -= (float)delta;
		}

		velocity.X = 0;
		if(Input.IsActionPressed("Left"))
		{
			velocity.X = -movementSpeed;
		}else if(Input.IsActionPressed("Right"))
		{
			velocity.X = movementSpeed;
		}

		if(CoyoteCount > 0 && BufferCount > 0)
		{
			velocity.Y = -jumpVelocity;
		}
		
		if(Input.IsActionJustReleased("Jump") && !IsOnFloor())
		{
			velocity.Y = velocity.Y * 0.1f;
		}

		if(CanWallJump)
		{

		}

		Velocity = velocity;
		MoveAndSlide();
	}
}

Any help would be greatly appreciated. Thanks in advance!

I don’t know why your Jump should work here.
you use BufferCount = Buffer; on jump,

Maybe 0.1 is too small to be noticed? What if you set velocity.y to 0 instead when releasing the jump button? (make sure to only do that if velocity.y is negative)

turns out it was something to do with the jump buffer, although I dont know what, because removing that fixed basically all my issues.

Thanks for all the help!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.