#Godot 3 move_and_slide in Godot 4

2 messages · Page 1 of 1 (latest)

odd nest
#

Hey all! I'm trying to replicate source style movement in Godot 4, but I've run into in an issue with the way the new CharacterBody3D handles slide collisions with move_and_slide. I've managed to get bhopping working correctly and surfing should work as a result of that, as it does in Godot 3, but in Godot 4, I seem to loose all horizontal momentum and just drop off the slope.

Is there any way to stop move_and_slide interacting with slide collisions like this? Or is there any code that I could use as a replacement for move_and_slide?

Example of whats happening in Godot 4: https://medal.tv/games/screen-capture/clips/1Nk1pxkWJG3dxD/d1337b95zlcz
Instead, the player should move smoothly across the ramp but doesn't because of the new slide collision handling.

Thanks in advance :D

8 Views. Watch Untitled and millions of other Screen Recording videos on Medal, the #1 Game Clip Platform.

▶ Play video
odd nest
#

For anyone in the future who may be looking for this too.

Thanks to this amazing person who already figured out how to do it in his game.

https://www.reddit.com/r/godot/comments/18lo8go/surfing_in_godot_available_to_everyone/
https://github.com/EricXu1728/Godot4SourceEngineMovement

This is the code that managed to solve everything

func move_and_slide_own() -> bool:
    var collided := false
    on_floor  = false

    #check floor
    var checkMotion := velocity * (1/60.0)
    checkMotion.y  -= gravity * (1/360.0)

    var testcol := move_and_collide(checkMotion, true)
    if testcol:
        var testNormal = testcol.get_normal()
        if testNormal.angle_to(up_direction) < floor_max_angle:
            on_floor = true

    # Loop performing the move
    var motion := velocity * get_delta_time()
    for step in max_slides:
        var _collision := move_and_collide(motion)
        if !_collision: break # No collision, so move has finished

        # Calculate velocity to slide along the surface
        var normal = _collision.get_normal()
        motion = _collision.get_remainder().slide(normal)
        velocity = velocity.slide(normal)

        # Collision has occurred
        collided = true

    return collided

func get_delta_time() -> float:
    if Engine.is_in_physics_frame():
        return get_physics_process_delta_time()

    return get_process_delta_time()
Reddit

Explore this post and more from the godot community

GitHub

Recreation of Source Engine Movement in godot4. Thank you to OakleyCyclops for making the Godot3 version which I messed around with. - GitHub - EricXu1728/Godot4SourceEngineMovement: Recreation of ...