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!