#Please help Fix Gap between collisions

3 messages · Page 1 of 1 (latest)

brave plaza
#

Code for Player:

    for i in get_slide_collision_count():
        var collision = get_slide_collision(i)
        if collision.get_collider() is MovableBlock:
            var movable_block = collision.get_collider()
            movable_block.velocity.x = move_toward(
                    movable_block.velocity.x,-collision.get_normal().x * (speed * 10), acceleration * delta
                )```

Code for Object:
````class_name MovableBlock
extends CharacterBody2D


@export var gravity_scale: float = 1.0
@export var friction: int = 1350

var gravity: float = ProjectSettings.get_setting("physics/2d/default_gravity")


func _physics_process(delta: float) -> void:
    if not is_on_floor():
        velocity.y += gravity * gravity_scale * delta
    
    velocity.x = move_toward(velocity.x, 0, friction * delta)
    move_and_slide()

Please help, I tried so many things, but it didn't work. Gap appears on high speed and on medium speed, but on slow speed it didn't appears.

fierce kettle
#

But with this approach you'll always have a gap, it's just very small with a small distance moved per physics frame