I'm new to Godot (and C# in general, but I use that because that's the language I'm learning in school, and I don't want to confuse myself with GDscript), and I tried to code a 2D player character (nothing too big, just moving, sprinting, jumping, and ground pounding), but when I got to the jumping mechanics, instead of player jumping, it just teleported upwards, and then glided downwards. And the ground pound just teleported me to the ground.
Here's the code:
using Godot;
using System;
public class Player : KinematicBody2D
{
private float speed = 600;
private float gravity = 500;
private float jumpForce = -5000;
//Basic variables for stuff
public override void _PhysicsProcess(float delta)
{
var move = Vector2.Zero;
var animatedSprite = GetNode<AnimatedSprite>("AnimatedSprite");
move.y = gravity;
//Other variables
if (Input.IsActionJustPressed("jump") && IsOnFloor())
{
move.y = jumpForce;
}
//Jumping
if (Input.IsActionPressed("left"))
{
move.x = -speed;
animatedSprite.Play("walk");
animatedSprite.FlipH = true;
if (Input.IsActionPressed("sprint"))
{
move.x = (-speed) + (-400);
}
}
if (Input.IsActionPressed("right"))
{
move.x = speed;
animatedSprite.Play("walk");
animatedSprite.FlipH = false;
if (Input.IsActionPressed("sprint"))
{
move.x = speed + 400;
}
}
//Movement and sprint
if(Input.IsActionJustPressed("pound"))
{
move.y = -jumpForce;
}
//Groundpound
MoveAndSlide(move, Vector2.Up);
}
}
The other thing with jumping is that I need a really big number to lift the player from the ground, so that jumpForce variable in the code is barely enough to lift the character.
A tried to tweak it a little bit, changed some numbers (I thought that maybe I just screwed up the variables), but that don't worked.