Whenever I run my project my sprite cannot jump because the IsOnFloor() method always returns false although my character is still in contact with the tiles. I very new to Godot so any help to configure my collision settings ? would be very useful. My other controls and collision works fine. enter image description here
using Godot;
using System;
public partial class Player1 : CharacterBody2D
{
private int gravity = 10;
private int maxSpeed = 500;
private int maxFallSpeed = 100;
public int speed = 200;
public int jumpForce = 100;
public Vector2 screenSize;
private bool jumpCheck = false;
private float jumpTimer= 0f;
private float maxJumpTime = 0.5f;
public override void _Ready()
{
screenSize = GetViewportRect().Size;
}
public override void _Process(double delta)
{
var velocity = Vector2.Zero;
if(IsOnFloor()==false)
{
velocity.Y += gravity * (float)delta;
}
if (IsOnFloor())
{
GD.Print("isonfloor = true");
}
else
{
GD.Print("isonfloor = false");
}
if (Input.IsActionPressed("left"))
{
GD.Print("left");
velocity.X -= speed;
}
if (Input.IsActionPressed("right"))
{
GD.Print("right");
velocity.X += speed;
}
if (Input.IsActionPressed("down"))
{
GD.Print("down");
velocity.Y += speed;
}
if(Input.IsActionPressed("jump") )
{
GD.Print("jump");
if(IsOnFloor() && !jumpCheck)
{
GD.Print("hello");
jumpCheck = true;
jumpTimer = 0f;
velocity.Y = -jumpForce;
}
else if (jumpCheck && jumpTimer < maxJumpTime)
{
GD.Print("jump2");
jumpTimer += (float)delta;
velocity.Y = -jumpForce;
}
else
{
GD.Print("jump3");
jumpCheck = false;
}
}
velocity = velocity.Normalized() * speed;
//MoveAndCollide(velocity);
bool collision = MoveAndCollide(velocity * (float)delta)!= null;
//Position += velocity * (float)delta;
}
}