I defined a function: func jump(): print(str("start jumping ", velocity.y )) velocity.y -= 0.1 #jump_vel print(str("ending jumping ", velocity.y ))
the problem is that the second print never get to be executed…mmm, any idea why does this happen?? after first print I just tryed to indicate:
velocity.y -=jump_force
with ump_force having this value: 0.1
But nothing changed
You are right. I am going to attach all my script then:
extends CharacterBody2D
###################
@export var speed = 50.0
@export var jump_vel =2000.0
@export var gravity_mul=1.0
@export var jump_count = 2
@export var jump_height:float
@export var jump_time_to_peak:float
@export var jump_time_to_descent:float
##################
#@onready var jump_heigth_timer = $JumpHigthTimer
#@onready var jump_buffer_timer = $BufferTimer
@onready var jump_velocity:float = ((2.0*jump_height)/jump_time_to_peak)*-1.0
@onready var jump_gravity:float = ((-2.0*jump_height)/(jump_time_to_peak*jump_time_to_peak))*-1.0
@onready var fall_gravity:float = ((-2.0*jump_height)/(jump_time_to_descent*jump_time_to_descent))*-1.0
var move_speed = 40.0
@onready var is_jumping = false
var last_direction=Vector2(1,0)
var gravity= ProjectSettings.get_setting("physics/2d/default_gravity")
######################
func _physics_process(delta):
######var direction= Input.get_vector("go_left","go_right","go_up","go_down")
var direction = Vector2(
Input.get_axis("go_left", "go_right"), # The x component of the Vector2 is the value returned to manage horizontal movement
0.0 # The y component of the Vector2 is the value returned to manage vertical movement : NO MOVING
)
velocity.x = direction.x*speed
######### velocity=direction*move_speed #<------CHECK THIS
if not is_on_floor():
print('falling down')
velocity.y += gravity * delta
else:
print('ON FLOOR. sei atterato')
##FORCE TO SET POSITION INSTEAD THA UODATE VELOCITY VECTOR
velocity.y += get_gravity_val()*delta
velocity.y +=get_gravity_val()*delta
if Input.is_action_just_pressed("Jump") and is_on_floor():
player_jump(delta,0.1)
#jump()
move_and_slide()
#var direction= Input.get_vector("go_down","go_up","go_right","go_left")
#move_and_slide()
#move_and_collide(velocity * delta)
if direction.length() > 0:
last_direction = direction
walk_anim(direction)
else:
idle_anim(last_direction)
move_and_slide()
#jump function
func jump():
print(str("start jumping ", velocity.y ))
velocity.y -= 0.1 #jump_vel
print(str("ending jumping ", velocity.y ))
func player_jump(_delta,jump_force):
#jump_heigth_timer.start()
print(str("starting height ", velocity.y ))
velocity.y -=jump_force
print(str("ending height ", velocity.y ))
func get_gravity_val() -> float:
return jump_gravity if velocity.y < 0.0 else fall_gravity
func walk_anim(direction):
if direction.x > 0:
$AnimatedSprite2D.play("walk_rigth")
elif direction.x < 0:
$AnimatedSprite2D.play("walk_left")
elif direction.y > 0:
$AnimatedSprite2D.play("walk_down")
elif direction.y < 0:
$AnimatedSprite2D.play("walk_up")
func idle_anim(direction):
if direction.x > 0:
$AnimatedSprite2D.play("idle_rigth")
elif direction.x < 0:
$AnimatedSprite2D.play("idle_left")
elif direction.y > 0:
$AnimatedSprite2D.play("idle_down")
elif direction.y < 0:
$AnimatedSprite2D.play("idle_up")
func jump():
print("This is the jump function.")
print("Starting velocity.y is ", velocity.y)
velocity.y -= 0.1
print("Ending velocity.y is ", velocity.y)