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.

in Engine
edited

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...

Player Code :
extends Actor

func physicsprocess(delta: float) -> void:
var direction: = getdirection()
velocity = calculate
movevelocity(velocity, direction, speed)
velocity = move
andslide(velocity, FLOORNORMAL)

func getdirection() -> Vector2:
return Vector2(
Input.get
actionstrength("moveright") - Input.getactionstrength("moveleft"),
-1.0 if Input.get
actionstrength("jump") and ison_floor() else 0.0
)

func calculatemovevelocity(
linearvelocity: Vector2,
speed: Vector2,
direction: Vector2
) -> Vector2:
var new
velocity: = linearvelocity
new
velocity.x = speed.x * direction.x
newvelocity.y += gravity * getphysicsprocessdeltatime()
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

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 physicsprocess(delta: float) -> void:

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

## func calclatemovevelocity(speed, direction, velocity):

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

func getdirection() -> Vector2:
return Vector2(
Input.get
actionstrength("moveright") - Input.getactionstrength("moveleft"),
-1.0 if Input.is
actionjustpressed("jump-up") and isonfloor() else 1.0
)

## warning-ignore:unreachable_code

func calculatemovevelocity(
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
``````

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.