If you have issue with the player bouncing on the floor while continuing to press the space bar, after you code the player like mine just change "action_pressed" by "action_just_pressed", that will fix it! :)
for anyone struggling on this episode here is a revised script: extends CharacterBody2D var input = 0.0 @export var speed = 100.0 @export var gravity = 10 # Variables for jumping var jump_count = 0 @export var max_jump = 2 @export var jump_force = 500 # Called when the node enters the scene tree for the first time. func _ready(): pass # Replace with function body. # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): movement(delta) func movement(delta): input = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left") if input != 0: velocity.x = input * speed if input > 0: $Sprite2D.scale.x = 1 else: $Sprite2D.scale.x = -1 $anim.play("walk") else: velocity.x = 0 $anim.play("idle") # Code related to jumping if is_on_floor(): jump_count = 0 if Input.is_action_just_pressed("ui_accept") and jump_count < max_jump: jump_count += 1 velocity.y = -jump_force if not is_on_floor(): if velocity.y < 0: $anim.play("jump") else: $anim.play("fall") # Apply gravity velocity.y += gravity move_and_slide()
ooo this is good i try to get ahead but on some cases like this i just did not know about things like the !is_on_floor stuff as well as where to play some code like the jump counter reset, still great tutorials so far! 👍
Great video. I'm having a problem, whenever I get to the part where I add ----&& jump_count < max_jump: ----for the double jump the line turns red and does not accept and says "Identifier jump_count not declared in current scope
Im also very new to coding but i beleave that you havent defined the variable jump_count. So basically missing "var jump_count = 0" or you have a typo in it.
Hello, I'm loving the tutorials, can you help me? For some reason my Player doesn't move from the platform with high gravity (10), so I keep trying with very low ones and it kind of gets stuck, you know. Has it ever happened to you?
Hello, I have an issue where my character only plays the first frame of the jump and fall animations I copied your code verbatim from the first video to here
Hi, my player isn't jumping. He keeps getting stuck on the ground and jitters when I press the jump key... I went back and forwards in the code, comparing with yours, I couldn't find a single thing that indicates a difference that may cause this problem... EDIT: It broke around 5:30, I continued coding because I thought it would be solved with the rest of the code, but it didin't... Here is my code: -------------------------- extends CharacterBody2D # Variables var input @export var speed = 100.0 @export var gravity = 10 ## Variables for jumping var jump_count = 0 @export var max_jump = 2 @export var jump_force = 500 func _ready() -> void: pass # Replace with function body. func _process(delta: float) -> void: input = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
if input != 0: # Right if input > 0: velocity.x = velocity.x + (speed * delta) velocity.x = clamp(speed, 100.0, speed) $Sprite2D.scale.x = 1 # Flip to right $anim.play("Walk") # Left if input < 0: velocity.x = velocity.x + (-speed * delta) velocity.x = clamp(-speed, 100.0, -speed) $Sprite2D.scale.x = -1 # Flip to left $anim.play("Walk")
if input == 0: velocity.x = 0 $anim.play("Idle")
if is_on_floor(): jump_count = 0
if !is_on_floor(): if velocity.y < 0: $anim.play("Jump") if velocity.y > 0: $anim.play("Fall")
turn on v-sync in Godot project preferences! the_process function runs as many times as your computer can handle. turning on v-sync will make it run at your monitors refresh rate. you can also just replace _process with _physics_process which will lock it to the physics frame-rate also set in project preferences.
Tres bonne vidéo merci ! petite question, quand je laisse s^pace appuié je jump en boucle, c'est possible de bloquer ca et que je doive réappuier sur space sur initié le jump
Bonjour, et merci :) Oui c'est possible de desactiver le jump, il y a plein de maniere de faire, la plus simple est de mettre 'action_just_pressed' au lieu d'"action_pressed" (il me semblait l'avoir mis dans la vidéo mais je l'ai oublié, je vais le rajouter dans une future video sur le wall jump),. Mais il y a d'autre maniere de faire, par exemple creer une variable (par exemple "is_pressed" et compter le nombre de fois ou ca a était pressé (par exemple 2) et ensuite creer une condition pour etre sure que si la touche a déja était pressé on ne peut pas re-sauter tout de suite. Mais apres il faut pouvoir réinitialisé le saut d'une autre maniere. Une autre maniere de faire est de creer un timer qui apres un certain temps desactive la touche si elle est pressé trop longtemps (par exemple au dessus de 1 seconde), ca marchera aussi :)
Thank you! :) I've made some try with procedural generation and it works well, I just have issue with layering different part of the level in a way that is logical, so I don't fully know yet. Maybe in a simple form, or maybe in a more complete form but later on :)
Here's my attempt at jumping logic: extends CharacterBody2D var input @export var speed = 150.0 @export var gravity = 1000 # variables for jumping var jump_count = 0 @export var max_jump_count = 2 @export var jump_force = 400 @export var max_jump_height = 75 var jump_timer = 0.0 var is_jumping = false # Called when the node enters the scene tree for the first time. func _ready(): pass # Replace with function body. # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): movement(delta) func movement(delta): input = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
If you have issue with the player bouncing on the floor while continuing to press the space bar, after you code the player like mine just change "action_pressed" by "action_just_pressed", that will fix it! :)
for anyone struggling on this episode here is a revised script:
extends CharacterBody2D
var input = 0.0
@export var speed = 100.0
@export var gravity = 10
# Variables for jumping
var jump_count = 0
@export var max_jump = 2
@export var jump_force = 500
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
movement(delta)
func movement(delta):
input = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
if input != 0:
velocity.x = input * speed
if input > 0:
$Sprite2D.scale.x = 1
else:
$Sprite2D.scale.x = -1
$anim.play("walk")
else:
velocity.x = 0
$anim.play("idle")
# Code related to jumping
if is_on_floor():
jump_count = 0
if Input.is_action_just_pressed("ui_accept") and jump_count < max_jump:
jump_count += 1
velocity.y = -jump_force
if not is_on_floor():
if velocity.y < 0:
$anim.play("jump")
else:
$anim.play("fall")
# Apply gravity
velocity.y += gravity
move_and_slide()
You, are a legend my good friend. This code worked perfectly and was so much more condensed and easy to adjust. My props to you!
ooo this is good i try to get ahead but on some cases like this i just did not know about things like the !is_on_floor stuff as well as where to play some code like the jump counter reset, still great tutorials so far! 👍
Great video. I'm having a problem, whenever I get to the part where I add ----&& jump_count < max_jump: ----for the double jump the line turns red and does not accept and says "Identifier jump_count not declared in current scope
Im also very new to coding but i beleave that you havent defined the variable jump_count. So basically missing "var jump_count = 0" or you have a typo in it.
At 6.02, if i launch the game i have a error that says: Invalid call. Nonexistend function 'Is_action_pressed' in base 'float'.
What do i do???!
nevermind it works now
i did the same thing lol
Hello, I'm loving the tutorials, can you help me? For some reason my Player doesn't move from the platform with high gravity (10), so I keep trying with very low ones and it kind of gets stuck, you know. Has it ever happened to you?
Hello, I have an issue where my character only plays the first frame of the jump and fall animations
I copied your code verbatim from the first video to here
Quite late, but did you check if looping is on for the animation?
Hi, my player isn't jumping. He keeps getting stuck on the ground and jitters when I press the jump key... I went back and forwards in the code, comparing with yours, I couldn't find a single thing that indicates a difference that may cause this problem...
EDIT: It broke around 5:30, I continued coding because I thought it would be solved with the rest of the code, but it didin't...
Here is my code:
--------------------------
extends CharacterBody2D
# Variables
var input
@export var speed = 100.0
@export var gravity = 10
## Variables for jumping
var jump_count = 0
@export var max_jump = 2
@export var jump_force = 500
func _ready() -> void:
pass # Replace with function body.
func _process(delta: float) -> void:
input = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
if input != 0:
# Right
if input > 0:
velocity.x = velocity.x + (speed * delta)
velocity.x = clamp(speed, 100.0, speed)
$Sprite2D.scale.x = 1 # Flip to right
$anim.play("Walk")
# Left
if input < 0:
velocity.x = velocity.x + (-speed * delta)
velocity.x = clamp(-speed, 100.0, -speed)
$Sprite2D.scale.x = -1 # Flip to left
$anim.play("Walk")
if input == 0:
velocity.x = 0
$anim.play("Idle")
if is_on_floor():
jump_count = 0
if !is_on_floor():
if velocity.y < 0:
$anim.play("Jump")
if velocity.y > 0:
$anim.play("Fall")
if Input.is_action_pressed("ui_accept") && is_on_floor() && jump_count < max_jump:
jump_count += 1
velocity.y -= jump_force
velocity.x = input
if !is_on_floor() && Input.is_action_just_pressed("ui_accept") && jump_count < max_jump:
jump_count += 1
velocity.y -= jump_force * 1.2
velocity.x = input
if !is_on_floor() && Input.is_action_just_released("ui_accept") && jump_count < max_jump:
velocity.y = gravity
velocity.x = input
else:
gravity_force()
gravity_force()
move_and_slide()
func gravity_force():
velocity.y += gravity
same here.. did u solve it
@@spelarnet not yet, I moved on to watching other tutorials
# Code for jumping
if is_on_floor():
jump_count = 0
if !is_on_floor():
if velocity.y < 0:
$AnimationPlayer.play("Jump")
if velocity.y > 0:
$AnimationPlayer.play("Fall")
if Input.is_action_just_pressed("ui_accept") && is_on_floor() && jump_count < max_jump:
jump_count += 1
velocity.y -= jump_force
velocity.x = input
if !is_on_floor() && Input.is_action_just_pressed("ui_accept") && jump_count < max_jump:
jump_count += 1
velocity.y -= jump_force * 1.3
velocity.y = clamp(-jump_force,-jump_force, 700)
velocity.x = input
else:
gravitatioal_force()
gravitatioal_force()
move_and_slide()
func gravitatioal_force():
velocity.y += gravity
Hi if you like you can use this code
@@DragonFlyFinal try this
if Input.is_action_just_pressed("ui_accept"):
if velocity.y
turn on v-sync in Godot project preferences! the_process function runs as many times as your computer can handle. turning on v-sync will make it run at your monitors refresh rate. you can also just replace _process with _physics_process which will lock it to the physics frame-rate also set in project preferences.
Tres bonne vidéo merci ! petite question, quand je laisse s^pace appuié je jump en boucle, c'est possible de bloquer ca et que je doive réappuier sur space sur initié le jump
Bonjour, et merci :) Oui c'est possible de desactiver le jump, il y a plein de maniere de faire, la plus simple est de mettre 'action_just_pressed' au lieu d'"action_pressed" (il me semblait l'avoir mis dans la vidéo mais je l'ai oublié, je vais le rajouter dans une future video sur le wall jump),.
Mais il y a d'autre maniere de faire, par exemple creer une variable (par exemple "is_pressed" et compter le nombre de fois ou ca a était pressé (par exemple 2) et ensuite creer une condition pour etre sure que si la touche a déja était pressé on ne peut pas re-sauter tout de suite. Mais apres il faut pouvoir réinitialisé le saut d'une autre maniere. Une autre maniere de faire est de creer un timer qui apres un certain temps desactive la touche si elle est pressé trop longtemps (par exemple au dessus de 1 seconde), ca marchera aussi :)
very cool, are u going to implement random levels? cheers
Thank you! :) I've made some try with procedural generation and it works well, I just have issue with layering different part of the level in a way that is logical, so I don't fully know yet. Maybe in a simple form, or maybe in a more complete form but later on :)
@@jeanmakesgames nice will be very cool keep videos coming :) Cheers
my char keeps jumping for infinte times
How many episodes will this be?
Around 20 :)
Toujours un plaisir malgré le fait que je sois sur Godot 3.5 🤣🤣
Haha Godot 3 est toujours bon en meme temps! :)
@@jeanmakesgames enfin j'ai godot 4.1 sur mon pc mais je vois pas trop l'intérêt de tout rapprendre😔🤣
Here's my attempt at jumping logic:
extends CharacterBody2D
var input
@export var speed = 150.0
@export var gravity = 1000
# variables for jumping
var jump_count = 0
@export var max_jump_count = 2
@export var jump_force = 400
@export var max_jump_height = 75
var jump_timer = 0.0
var is_jumping = false
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
movement(delta)
func movement(delta):
input = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
if input != 0:
if input > 0:
velocity.x += speed * delta
velocity.x = clamp(speed, 150.0, speed)
$Sprite2D.scale.x = 1
$anim.play("Walk")
if input < 0:
velocity.x -= speed * delta
velocity.x = clamp(-speed, -150.0, -speed)
$Sprite2D.scale.x = -1
$anim.play("Walk")
if input == 0:
velocity.x = 0
$anim.play("Idle")
if is_on_floor():
jump_count = 0
is_jumping = false
if !is_on_floor():
if velocity.y < 0:
$anim.play("Jump")
else:
$anim.play("Fall")
if Input.is_action_just_pressed("ui_accept") && jump_count < max_jump_count:
jump_count += 1
velocity.y = -jump_force
jump_timer = 0.0
is_jumping = true
gravity_force(delta)
move_and_slide()
func gravity_force(delta):
if not is_jumping:
velocity.y += gravity * delta
else:
if jump_timer * jump_force < max_jump_height && Input.is_action_pressed("ui_accept"):
jump_timer += delta
else:
velocity.y = velocity.y/3
is_jumping = false
Your code is so cool, you fixed the error that occurs in the double when being close to the ground