Hi Nathan,
Really appreciate your tutorials. I'm able to understand everything you're explaining. The way I follow your tutorials is I watch 1 video first and than work in godot to try and retain what you're teaching. I'm not able to figure out why Interrupting Jump is not working for me. I've checked the code multiple times. Please check the code below.
extends KinematicBody2D
class_name Actor
const FLOOR_NORMAL = Vector2.UP
export var speed: = Vector2(300, 1000)
export var gravity: = 4000.0
var velocity: = Vector2.ZERO
extends Actor
func _physics_process(delta: float) -> void:
var is_jump_interrupted: = Input.is_action_just_released("jump") and velocity.y < 0.0
var direction = get_direction()
velocity = calculate_move_velocity(velocity, direction, speed, is_jump_interrupted)
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_just_pressed("jump") and is_on_floor() else 0.0
)
func calculate_move_velocity(
linear_velocity: Vector2,
direction: Vector2,
speed: Vector2,
is_jump_interrupted: bool
) -> Vector2:
var new_velocity: = linear_velocity
new_velocity.x = speed.x * direction.x
new_velocity.y += gravity * get_process_delta_time()
if direction.y == -1.0:
new_velocity.y = speed.y * direction.y
if is_jump_interrupted:
new_velocity.y == 0.0
return new_velocity
Waiting for your response.
Hi,
I'm unable to figure out the error just from reading the code either at the moment. I could look into the project directly if you'd like? I'd need you to upload it as a .zip archive to the cloud service or upload service of your choice.
Hi,
Just try this:
new_velocity.y = 0.0
The point is, you were trying to use '==' comparison signal instead of the attribution signal.
Ah great catch! I hadn't spotted the `==`. Removing one = should solve the issue.