0

According to this video: https://www.youtube.com/watch?v=Mc13Z2gboEk, so far, at 1:02:44, my character is supposed to be jumping, but on my screen it isn't.

Here is the code I have for the Player script:

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.is_action_pressed("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

Here is the code for the Actor script:

extends KinematicBody2D
class_name Actor
    
const FLOOR_NORMAL: = Vector2.UP

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

I have put in the correct input maps, double checked it, un-added and re-added, no luck.

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
kal
  • 11
  • 1
  • 2

1 Answers1

0

When you call calculate_move_velocity, you have the arguments in this order:

  • velocity.
  • direction.
  • speed.

Here:

    velocity = calculate_move_velocity(velocity, direction, speed)

But your declaration of calculate_move_velocity has the parameters in this order:

  • linear_velocity.
  • speed.
  • direction.

Here:

func calculate_move_velocity(
        linear_velocity: Vector2,
        speed: Vector2,
        direction: Vector2
    ) -> Vector2:

So you are passing:

  • velocity into linear_velocity.
  • direction into speed.
  • speed into direction.

If that sounds correct to you, I don't know what to tell you.

I see this issue with a fresh mind, not arriving from dealing with the code. You probably just needed a good rest and you would have seen it.

Theraot
  • 31,890
  • 5
  • 57
  • 86
  • Hey, thanks for clarifying, turns out you were right, I completely missed it, thanks a lot! appreciate it!! – kal Feb 02 '22 at 23:07