#2.5D Sliding

27 messages · Page 1 of 1 (latest)

zinc apex
#

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```
zinc apex
#

_ _

stone flax
#

Is it a 2d game with a 3d perspective?

queen yarrow
#

you can use get_floor_angle() and calculate from that

zinc apex
#

Is there any way to decetc weather it is at an up or down angle? (Ik that depends on the direction the player is facing but might as well ask) @queen yarrow

queen yarrow
#

you have the normal of the floor, so if you compare it to the player facing direction you can determine the slope

#

probably a dot product

zinc apex
#

Example because I barely understand what a dot product is. (lol i gota take more math classes)

#

@queen yarrow

queen yarrow
#

just a number proportional to the angle between two vectors

#

you'll figure it out

zinc apex
queen yarrow
#

yea

zinc apex
#

Sorry for all the questions, I am very unfamilier with Vectors and stuff

#

ok

queen yarrow
#

the forward of the player is -player.transform.basis.z

zinc apex
queen yarrow
#

your player isn't rotating then

zinc apex
#

ohhh

#

i can quickly make it do tah

#

that

queen yarrow
#

any vector that points in the 'forward' direction will do

#

you must have like a velocity vector or something

zinc apex
#

I have been working on this for houers and still figure out how to get the floor angle. Right now I have a way to detect which direction the player is facing (it is a static value that is positive if facing left, negative if right) but I can not for the life of me figure out how to use that i have tryed get_floor_normal().dot(direction) and the output seems relitively random 😦 Any help?

zinc apex
#

I feel like such an idiot lol, I have worked with Godot for years, I have just never had to do something like this before