+2 votes

Basically I just have no idea how to implement acceleration and deceleration, and furthermore, when the player accels and decels it should treat the slope so you would glide with acceleration up the slope the same distance as you would down the slope. This would work well with my current system of moving up and down slopes at the same speed.

Thanks in advance for the help!

This is my current system, but it seems very bad.

if Input.is_action_pressed("move_forward"):
    velocity.x -= sin(rotation.y) * acceleration
    velocity.z -= cos(rotation.y) * acceleration
if Input.is_action_pressed("move_left"):
    velocity.x -= cos(rotation.y) * acceleration
    velocity.z += sin(rotation.y) * acceleration
if Input.is_action_pressed("move_backward"):
    velocity.x += sin(rotation.y) * acceleration
    velocity.z += cos(rotation.y) * acceleration
if Input.is_action_pressed("move_right"):
    velocity.x += cos(rotation.y) * acceleration
    velocity.z -= sin(rotation.y) * acceleration

if velocity.x != 0 || velocity.z != 0:
    if is_on_floor(): #friction!
        velocity.z *= 0.9;
        velocity.x *= 0.9;

    if abs(velocity.x) <= 0.0001:
        velocity.x = 0;
    if abs(velocity.z) <= 0.0001:
        velocity.z = 0;
in Engine by (52 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.