0 votes

A little preface - I am about 3 weeks into my coding/gamedev journey.
Also: I added a short video demonstrating the issue.

I have a simple state machine that handles animations, and things like falling, wall sliding, jumping, falling. all good, it works beautifully.

My player character node is basically just a variables/functions container, and I have my max speed reached via acceleration, and clamped to the max speed's positive and negative value.

Without snap, movement works as I expect, my variables alter accel, friction, top speed, etc. Jumping, wallslides, all that.

But it's not acting the way I would expect. My movement speed gets clamped to a much lower value when snap is enabled.

When I jump with snap enabled, I move at the normal speed on the x axis, and acceleration/drag/gravity act normally.

Snap motion code - I have UP defined as a variable (Vector2.UP) higher in the code.

motion = move_and_slide_with_snap(motion, snap_vector, UP, true, 1, deg2rad(60))

Without snap -

  *(motion = move_and_slide(motion, Vector2(0, -1), true) # This is commented out in the code currently.*

I really don't want to forgo using stairs, but if I can't wrap my head around this, I might have to.

If you need more of the code, or variables, let me know. I didn't want to dump the entire 200+ lines here.

Below is my left/right movement code. Player is a KinematicBody2D. I use a combination of Raycasts and CollisionShape2D to know what and where the Player is touching the game world.

func _handle_movement(delta): #Movement left/right and define Facing direction.
var x_input = Input.get_action_strength("right") - Input.get_action_strength("left")
if x_input != 0:
    motion.x += x_input * ACCELERATION * MAX_SPEED * delta
    motion.x = clamp(motion.x, -MAX_SPEED, MAX_SPEED)
    sprite.flip_h = x_input < 0
    facing = x_input
    if is_on_floor():
elif x_input == 0:
    motion.x = lerp(motion.x, 0, delta*FRICTION)
    if is_on_floor():

This is my move and slide code, grounded check, and gravity code.

func _apply_movement():

motion = move_and_slide_with_snap(motion, snap_vector, UP, true, 1, deg2rad(60))

if move_direction == 0 && abs(motion.x) < SLOPE_STOP_THRESHOLD:
    motion.x = 0

var was_grounded = is_grounded
is_grounded = is_on_floor()

if was_grounded == null || is_grounded != was_grounded:
    emit_signal("grounded_updated", is_grounded)

func _apply_gravity(delta):
    motion.y += GRAVITY * delta
    if is_jumping && motion.y >= 0:
        is_jumping = false

I wanted to implement staircases into my game, however, when moveandslide is used without snap, I "ramp" off of slopes, even with settings meant to stop it.

My brain is having a hard time keeping up the farther in I go - I have like, zero coding experience, I'm just an artist that sucks at networking.

Godot version 3.3.2.stable
in Engine by (14 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.