Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bunny hopp speed boost on slanted terrain. #1

Open
DocAndus opened this issue May 14, 2024 · 3 comments
Open

Bunny hopp speed boost on slanted terrain. #1

DocAndus opened this issue May 14, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@DocAndus
Copy link

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
Copy link
Owner

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 majikayogames added the enhancement New feature or request label May 14, 2024
@majikayogames
Copy link
Owner

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
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants