majikayogames / SimpleFPSController

Creative Commons Zero v1.0 Universal
25 stars 3 forks source link

Bunny hopp speed boost on slanted terrain. #1

Open DocAndus opened 1 month ago

DocAndus commented 1 month ago

Bunny hopping should multiply speed by a bit when landing on a slanted surface while going downhill.

This is how I think it might work,

air time or velocity * Surfase degrees

I belive you also lose speed while bunny hopping up a hill.

So a flat terrain would be a 1X multeplier, while downward might capped at max 3X multiplyer and up min 0.5X loss

The multiplier would probobly be a linear interpolation (LERP) If I use that term correctly.

Video showcasing it https://www.youtube.com/watch?v=aH633mHw8UM

Side note. I also tested falling straight down fron the sky (god mode) and landing a bunny hopp on flat terrein. It gave no speed boost

"Crouching gives more speedboost because of airtime or velocity gain but is way harder to do and you can't uncrouch"

majikayogames commented 1 month ago

Thank you. Will make a note of this to add to further improve the bhop physics. Leaving this here to remind me. Have a bunch of other tutorials to get through first. If anyone comes across this and has any idea how this might be implemented, we can discuss this here. If no one else does I will take a closer look when I have time.

majikayogames commented 1 month ago

Got another comment I think that relates to this on one of my videos:

How would one implement ramp sliding like in source games? Like when you hit a slant/ramp straight on at a high speed, you just keep sliding. Currently in this project the player character just slows down aggressively.

It looks like a couple mechanics may depend on the current angle of the floor you're on.

DocAndus commented 1 month ago

I made a function that kind of works for now, though it is far from perfect. You'll get a boost applied by how much the normal is tilted, it's also applied when jumping straight up on a slope.

@onready var slope_detect = $StairsBelowRay #Raycast under Player I used the same as for detecting stairs below, this one might have a diffrent name for you.
func apply_slope_boost():
    if slope_detect.is_colliding():
        var normal = slope_detect.get_collision_normal()
        if normal.dot(Vector3.UP) < 1.0:  # What angle boost will apply on
            var boost_dir = normal
            boost_dir.y = 0  # Clamp Y so no jump good
            boost_dir = boost_dir.normalized()
            # Calculate the steepness factor based on the slope angle
            var face_slant = 1.2 - normal.dot(Vector3.UP) #Change float for boost amount.

            # Calculate the current velocity horisontal and ignores verical
            var slope_boost = velocity.length() * face_slant

            velocity += boost_dir * slope_boost

And start the function in _physics_process handeling jump mechanic

    if not _handle_noclip(delta) and not _handle_ladder_physics(delta):
        if not _handle_water_physics(delta):
            if is_on_floor():
                if Input.is_action_just_pressed("jump") or (auto_bhop and Input.is_action_pressed("jump")):
                    self.velocity.y = jump_velocity
INSERT- -----   -----   -----   --->    apply_slope_boost()
                _handle_ground_physics(delta)