Jump Pad

There doesn’t seen to be any difference in the jump height and the jump Pad height, not sure what’s going on

Player script

extends CharacterBody2D
class_name Player

@export var gravity = 400
@export var jump_force = 200
@export var speed = 125
@onready var animated_sprite = $AnimatedSprite2D

#func _process(delta):
#if Input.is_action_just_pressed(“move_right”):
#animated_sprite.play(“run”)
func _physics_process(delta):
if is_on_floor()==false:
velocity.y += gravity * delta
if velocity.y > 500:
velocity.y = 500

if Input.is_action_just_pressed("jump"): #&& is_on_floor():
		#velocity.y = -jump_force
		jump(jump_force)
	
var direction = Input.get_axis("move_left", "move_right")
if direction != 0:
		animated_sprite.flip_h = (direction == -1)

velocity.x = direction * speed
move_and_slide()

update_animations(direction)

func jump(force):
velocity.y = -jump_force

func update_animations(direction):
if is_on_floor():
if direction == 0:
animated_sprite.play(“idle”)
else:
animated_sprite.play(“run”)
else:
if velocity.y < 0:
animated_sprite.play(“jump”)
else:
if velocity.y > 0:
animated_sprite.play(“fall”)

Jump pad script

extends Area2D

@export var jump_force = 300

@onready var animated_sprite = $AnimatedSprite2D

func _on_body_entered(body):
if body is Player:
animated_sprite.play(“jump”)
body.jump(jump_force)

At first glance, your code looks ok from here. The first thing that comes to mind is that you might have a different value set up in the Inspector - that won’t be reflected in the code because that’s only a default value, and the script can’t indicate when the default value is being overwritten. If, for example, you’ve set the jump pad’s jump_force to 200 in the inspector, looking at the script will be misleading.

If that’s not what’s happening, I’d try jacking up the jump pad’s jump_force; if your player puts a new crater in the moon, then you have your answer =)

But you probably won’t see that if you’re not noticing a difference between 200 and 300. The best thing I could suggest at that point would be to insert a breakpoint and check the values in each case, but try the other stuff first and see if that’s the issue.

The breakpoint is a good idea, I might try print some values to see what it really is. I guess debugging is all part of it. Thanks

1 Like

Privacy & Terms