Sunday, April 14, 2024
HomeGame Developmentc# - Learn how to make the leaping/floor pounding clean in Godot?

c# – Learn how to make the leaping/floor pounding clean in Godot?


I am new to Godot (and C# basically, however I exploit that as a result of that is the language I am studying in class, and I do not wish to confuse myself with GDscript), and I attempted to code a 2D participant character (nothing too huge, simply shifting, sprinting, leaping, and floor pounding), however once I received to the leaping mechanics, as an alternative of participant leaping, it simply teleported upwards, after which glided downwards. And the bottom pound simply teleported me to the bottom.

This is the code:

utilizing Godot;
utilizing System;

public class Participant : KinematicBody2D
{
    personal float pace = 600;
    personal float gravity = 500;
    personal float jumpForce = -5000;
    //Primary variables for stuff

    public override void _PhysicsProcess(float delta)
    {
        var transfer = Vector2.Zero;
        var animatedSprite = GetNode<AnimatedSprite>("AnimatedSprite");
        transfer.y = gravity;
        //Different variables
        
        if (Enter.IsActionJustPressed("leap") && IsOnFloor())
        {
            transfer.y = jumpForce;
        }
        //Leaping
        
        if (Enter.IsActionPressed("left"))
        {
            transfer.x = -speed;
            animatedSprite.Play("stroll");
            animatedSprite.FlipH = true;
            
            if (Enter.IsActionPressed("dash"))
            {
                transfer.x = (-speed) + (-400);
            }
        }
        if (Enter.IsActionPressed("proper"))
        {
            transfer.x = pace;
            animatedSprite.Play("stroll");
            animatedSprite.FlipH = false;
            
            if (Enter.IsActionPressed("dash"))
            {
                transfer.x = pace + 400;
            }
        }
                //Motion and dash

        if(Enter.IsActionJustPressed("pound"))
        {
            transfer.y = -jumpForce;
        }
        //Groundpound
        
        MoveAndSlide(transfer, Vector2.Up);
    }
}

The opposite factor with leaping is that I would like a very huge quantity to carry the participant from the bottom, in order that jumpForce variable within the code is barely sufficient to carry the character.

A tried to tweak it just a little bit, modified some numbers (I assumed that possibly I simply screwed up the variables), however that do not labored.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments

Arnavsijapati on Planet of Lana – Beta Demo
Jai Kishor Upadhyay on Planet of Lana – Beta Demo