0 votes

At the moment my character will slide around an object whenever I run into one(I don't mean it'll just go around it, I mean whenever I run into something it slides awkwardly. If you still don't understand here's a video file: https://cdn.discordapp.com/attachments/756466310526795817/785322586186711080/2020-12-06_20-50-45.mp4). It's very disorienting and weird. I'll put the code below this so if there is a way to add this I would greatly appreciate it.

const ACCELERATION = 500
const MAX_SPEED = 80
const FRICTION = 500

func move_state(delta):
    var input_vector = Vector2.ZERO
    input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
    input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
    input_vector = input_vector.normalized()

    if input_vector != Vector2.ZERO:
        animationTree.set("parameters/Idle/blend_position", input_vector)
        animationTree.set("parameters/Walk/blend_position", input_vector)
        animationTree.set("parameters/Attack/blend_position", input_vector)
        velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
        velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)

    velocity = move_and_slide(velocity)
in Engine by (38 points)

1 Answer

0 votes

I think this might work.

var collision
collision = move_and_collide(velocity*delta)
if collision != null:
    velocity = Vector2(0,0)

But it uses moveandcollide() instead of moveandslide(). I think you can implemet using moveandslide() too.

by (22 points)

You will have to replace:
velocity = move_and_slide(velocity) with the above code

no, if I use this I can't move at all :/

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 Frequently asked questions and 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 [email protected] with your username.