0 votes

I'm having problem with collision detection using test_move, as seem in the gif.

The issue seem to be solved when I add 0.1 to rel_vec.x, this can too be seem on the gif, the collision with the right wall is using the vector with added value, and the left is not.

The const player.JUMPCORNERCORRECTION is 8, the same size of a tile.

Am I using the function wrongly?

Here's the code:

extends "res://characters/player/states/motion/motion.gd"

const HIGH_JUMP_FORCE = -180

func enter():
    player.velocity.y = HIGH_JUMP_FORCE

func update(delta: float):
    var input_dir = player.get_input_direction()

    _handle_horizontal_accel(input_dir.x, delta)
    player.flip_character(input_dir.x)

    # Half gravity jump peak
    if (player.velocity.y < player.JUMP_PEAK_THRESHOLD):
        player.apply_gravity(delta)
        add_trail_point()
    else:
        player.apply_gravity(delta, player.JUMP_PEAK_GRAVITY_SCALE)
        add_trail_point(Color.teal)

    var delta_y = player.velocity.y * delta
    if (player.velocity.y < 0 && player.test_move(player.global_transform, Vector2(0, delta_y))):
        _correct_jump_corner(player.JUMP_CORNER_CORRECTION, input_dir.x, delta_y)

    player.move(player.velocity, false)

func _correct_jump_corner(amount: int, dir: float, delta: float):
    if (dir >= 0):
        for i in range(1, amount + 1):
            if (!player.test_move(player.global_transform.translated(
                Vector2(i, 0)), Vector2(0.1, delta))):
                player.translate(Vector2(i, 0))
                return

    if (dir <= 0):
        for i in range(-1, -(amount + 1), -1):
            if (!player.test_move(player.global_transform.translated(
                Vector2(i, 0)), Vector2(0, delta))):
                player.translate(Vector2(i, 0))
                return
in Engine by (18 points)
retagged by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.