Godot Version
godot 4.2.1 stable-mono win64
Question
I have been working on a small action platformer in godot 4 with c#, and so far all I have put together a very basic platformer controller, and I was wondering how I might go about adding the ability to dash to my script, as whatever I am trying now does not seem to work. Here is the script in question:
`using Godot;
using System;
public partial class Player : CharacterBody2D
{
public bool CanDash = true;
public int dashes = 1;
public float movementSpeed = 150f;
public float jumpVelocity = 200f;
public float CoyoteTime = 0.4f;
public float CoyoteCount;
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;
dashes = 1;
}else{
CoyoteCount -= (float)delta;
}
velocity.X = 0;
if(Input.IsActionPressed("Left"))
{
velocity.X = Mathf.Lerp(velocity.X, -movementSpeed, 0.8f);
}else if(Input.IsActionPressed("Right"))
{
velocity.X = Mathf.Lerp(velocity.X, movementSpeed, 0.8f);
}
if(CoyoteCount > 0 && Input.IsActionJustPressed("Jump"))
{
velocity.Y = -jumpVelocity;
CoyoteCount = 0;
}
if(Input.IsActionJustReleased("Jump") && velocity.Y < 0)
{
velocity.Y = velocity.Y * 0.1f;
}
if(CanDash)
{
if(Input.IsActionJustPressed("Jump"))
{
if(!IsOnFloor())
{
if(dashes > 0)
{
velocity.X += movementSpeed*10;
dashes -= 1;
}
}
}
}
Velocity = velocity;
MoveAndSlide();
}
}`
my dash currntly just adds an arbitrary value to the velocity, but for some reason this has little to no effect on the characters actual movement, besides just snapping them forward a couple pixels. Any help would be greatly apprecieated.