# Can someone help me with a problem from the tutorial "make your first 2D game with Godot"

Attention Topic was automatically imported from the old Question2Answer platform.

I was following the video “make your first 2d game with Godot” and while I was working on the part called “Preventing the velocity from resetting every frame” i noticed that my “player character” wouldn’t jump after I looked threw the comments and found the line replacement for 13 on the player and it still wouldn’t work.

Can you upload your project or at least the relevant portions of code? There can be a lot of reasons why something like a jump isn’t working and I won’t guess…

njamster | 2020-08-08 21:07

Player Code :
extends Actor

func _physics_process(delta: float) → void:
var direction: = get_direction()
velocity = calculate_move_velocity(velocity, direction, speed)
velocity = move_and_slide(velocity, FLOOR_NORMAL)

func get_direction() → Vector2:
return Vector2(
Input.get_action_strength(“move_right”) - Input.get_action_strength(“move_left”),
-1.0 if Input.get_action_strength(“jump”) and is_on_floor() else 0.0
)

func calculate_move_velocity(
linear_velocity: Vector2,
speed: Vector2,
direction: Vector2
) → Vector2:
var new_velocity: = linear_velocity
new_velocity.x = speed.x * direction.x
new_velocity.y += gravity * get_physics_process_delta_time()
if direction.y == -1.0:
new_velocity.y = speed.y * direction.y
return new_velocity

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
Actor Code:
extends KinematicBody2D
class_name Actor

const FLOOR_NORMAL: = Vector2.UP

export var speed: = Vector2(300.0,1000.0)
export var gravity: = 4000.0

var velocity: = Vector2.ZERO

SpeedStinger246 | 2020-08-09 09:51

below is what i did (notice there is a spelling mistake in calculate hece i changed the same in line 9)

# extend the parent note aCTOR.gd

extends Actor

func _physics_process(delta: float) → void:

``````var direction: = get_direction()
``````

# defining calclate_move_velocity sice it was crashing with parse error I declared it here, still the gravity isn’t working

#func calclate_move_velocity(speed, direction, velocity):

``````velocity = calclate_move_velocity(speed, direction, velocity)
velocity = move_and_slide(velocity)
``````

func get_direction() → Vector2:
return Vector2(
Input.get_action_strength(“move_right”) - Input.get_action_strength(“move_left”),
-1.0 if Input.is_action_just_pressed(“jump-up”) and is_on_floor() else 1.0
)

# warning-ignore:unreachable_code

func calculate_move_velocity(
speed: Vector2,
direction: Vector2,
linear_velocity: Vector2
) → Vector2:

# new velocity

``````	var new_velocity: = linear_velocity
new_velocity.x = speed.x * direction.x
new_velocity.y += gravity * get_physics_process_delta_time()
if direction.y == -1.0:
velocity.y = speed.y * direction.y

return speed * direction
``````

melon_man_of _math | 2023-01-08 15:24

You mixed up the order of arguments: your `calculate_move_velocity`-function expects `speed` as the second and `direction` as the third argument, but you passed `direction` as the second one and `speed` as the third one instead.