0 votes
Hi, first of all I want to mention that English is not my mother tongue, and that I am only 16, so I don't have any prior programming experience, although, I understand what certain thing do :)))

I am working on my first video game, and I want to implement a "Varying Jump Height Mechanic" for my character. I try to make the controls feel like a hybrid between "Super Mario Bros 1, Super Castlevania IV, Super Meat-Boy and Mega Man 7"

For now, I managed to give the player the desired air control, however, without having   the possibility to control the height of the jump, the movement will feel quite sloppy.

One more thing before I give you the script, all the sprites are placeholders for now if that has to do with anything.

extends KinematicBody2D

const SPEED = 125
const GRAVITY = 18
const JUMP_POWER = -325
const FLOOR = Vector2(0, -1)

const FIREBALL = preload("res://Fireball.tscn")

var velocity = Vector2()

var on_ground = false

var is_dead = false

func physicsprocess(delta):

if is_dead == false:


     if Input. is_action_pressed("ui_right"):
         velocity.x = SPEED
         $AnimatedSprite.play("run")
         $AnimatedSprite.flip_h = true
         if sign($Position2D.position.x) == -1:
             $Position2D.position.x *= -1

     elif Input. is_action_pressed("ui_left"):
         velocity.x = -SPEED
         $AnimatedSprite.play("run") 
         $AnimatedSprite.flip_h = false
         if sign($Position2D.position.x) == 1:
              $Position2D.position.x *= -1

     else:
         velocity.x = 0
         if on_ground == true:
             $AnimatedSprite.play("idle")

     if Input. is_action_pressed("ui_up"):
         if on_ground == true:
             velocity.y = JUMP_POWER
             on_ground = false 




     if Input. is_action_just_pressed("ui_focus_next"):
         var fireball = FIREBALL.instance()
         if sign($Position2D.position.x) == 1:
             fireball.set_fireball_direction(1)
         else:
             fireball.set_fireball_direction(-1)


         get_parent().add_child(fireball)
         fireball.position = $Position2D.global_position

     velocity.y += GRAVITY

     if is_on_floor():
         on_ground = true 
     else:
         on_ground = false
         if velocity.y < 0:
             $AnimatedSprite.play("jump")
         else:
             $AnimatedSprite.play("fall")

     velocity = move_and_slide(velocity, FLOOR)

     if get_slide_count() > 0:
         for i in range(get_slide_count()):
             if "Enemy" in get_slide_collision(i).collider.name:
                 dead()


     if Input. is_action_just_pressed("ui_cancel"):
         get_tree().change_scene("titlescreen.tscn")

func dead():
is_dead = true
velocity = Vector2(0, 0)
$AnimatedSprite.play("dead")
$CollisionShape2D.disabled = true
$Timer.start()

func onTimertimeout():
get
tree().change_scene("titlescreen.tscn")

...............................................................

 I hope that I can find someone that is kind, and patient enough to help me with this issue, I would do it myself, but like I said I am 16 so I do not have any experience.
in Engine by (12 points)
recategorized by

1 Answer

0 votes

Try using varying jump power then

by (1,051 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.