### Godot Version

4.2.2

### Question

I’m just trying to get the basics of movement down for a side scrolling 2D platformer when I got stuck on coding the jumping. I can’t seem to understand on how to get it to work. I tried watching tutorials to get close, but now my character only does a short hop. Here is my code, if I’m missing something then please let me know.

using Godot;

using System;

using System.Security.Cryptography.X509Certificates;

public partial class player : CharacterBody2D

{

[Signal]

public delegate void HitEventHandler();

```
[Export]
public int speed {get; set;} = 500;
[Export]
float jump_height;
[Export]
float jump_time_to_peak;
[Export]
float jump_time_to_descent;
float jump_velocity;
float jump_gravity;
float fall_gravity;
bool is_on_floor;
public Vector2 ScreenSize;
public override void _Ready()
{
ScreenSize = GetViewportRect().Size;
jump_velocity = ((2 * jump_height) / jump_time_to_peak) *-1;
jump_gravity = ((-2 * jump_height) / (jump_time_to_peak * jump_time_to_peak)) *-1;
fall_gravity = ((-2 * jump_height) / (jump_time_to_descent * jump_time_to_descent)) *-1;
}
public override void _PhysicsProcess(double delta)
{
var velocity = Vector2.Zero;
is_on_floor = IsOnFloor();
if (Input.IsActionPressed("right")){
velocity.X += 1;
}
if (Input.IsActionPressed("left")){
velocity.X += -1;
}
if(Input.IsActionJustPressed("jump") && is_on_floor)
{
velocity.Y = jump_velocity;
}
if(!is_on_floor)
{
velocity.Y += GetGravity(velocity.Y) * (float)delta;
}
MoveAndSlide();
var animatedSprite2D = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
animatedSprite2D.Play();
if (velocity.Length() > 0){
velocity = velocity.Normalized() * speed;
}
Position += velocity * (float)delta;
Position = new Vector2(x: Mathf.Clamp(Position.X, 0, ScreenSize.X), y: Mathf.Clamp(Position.Y, 0, ScreenSize.Y));
if (velocity.X != 0)
{
animatedSprite2D.Animation = "walk";
animatedSprite2D.FlipV = false;
animatedSprite2D.FlipH = velocity.X < 0;
}
if (velocity.X == 0)
{
animatedSprite2D.Animation = "idle";
animatedSprite2D.FlipV = false;
if(Input.IsActionJustReleased("left"))
{
animatedSprite2D.FlipH = true;
}
}
}
public float GetGravity(float v)
{
if(v < 0)
{
return jump_gravity;
}
else
{
return fall_gravity;
}
}
```