Hello, I am trying to make a 2.5D game for a school literature project, and I am trying to implement a sliding mechanic. I have a decent baseline made, but I really have no clue how I would go about making it so that the player decelerates more when going uphill, and decelerates when going uphill. Would anyone be able to show me how to do this? Thank you!You can send me an outline of what I need to do and the function I need or the code you would use for this, I appreciate any help.
Here is the relevant code:
Variables
# Movement:
@export var gravity : float = 16.0
@export var speed : float = 6.0
@export var acceleration : float = 8
@export var deceleration : float = 11
@export var slide_deceleration : float = 0.5
@export_range(0.0, 2, 0.05) var air_control := 1.5
@export var jump_height : float = 7.0
@export var crouch_speed : float = 2.0
@export var min_slide_speed : float = 3.0
var target := Vector2()
# Camera:
@export var camera_zoom : float = 30.0
@export var max_zoom : float = 30
@export var zoom_speed : float = 0.5
@onready var rest_x := Vector2($Camera3D.position.x, $Camera3D.position.x)```
# Current Crouch Script
*This is the code that needs to be changed to make the player accelerate when going downhill and decelerate more when going uphill.*
```c++
func accelerate(delta):
var temp_vel := Vector2(velocity.z, velocity.y)
temp_vel.y = 0
var temp_accel : float
if !Input.is_action_pressed("crouch"):
target = input_axis * speed
else:
target = input_axis * crouch_speed
if abs(input_axis.dot(temp_vel)) > 0:
temp_accel = acceleration
if !is_on_floor():
temp_accel = air_control
elif is_on_floor():
temp_accel = deceleration
if Input.is_action_pressed("crouch") and min_slide_speed < abs(velocity.z):
temp_accel = slide_deceleration
temp_vel = temp_vel.lerp(target, temp_accel * delta)
velocity.z = temp_vel.x```