The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

I'm new at learning godot and i really need help with this :/

Whenever i walk "pressing" myself into a wall, my character really slows down. Is there anything i can do to solve this problem?

I've created my walls as a tilemap(no code, only a collision shape and the sprite)
(btw, sorry for my bad english)
my KinematicBody2D(my character sprite) code is:
.
.
extends KinematicBody2D

export var speed : int = 200

func physicsprocess(delta):
var direction = Vector2()

direction.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
direction.y = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")

if abs(direction.x) == 1 and abs(direction.y) == 1:
    direction.normalized()

var movement = speed * direction * delta

move_and_collide(movement)
in Engine by (16 points)

2 Answers

+2 votes
Best answer

So, im guessing this is a top down game. If you dont want the character slow down or stops if colliding a wall, use move_and_slide insteado of move_and_collide.

I mean change this:

var movement = speed*direction*delta
move_and_collide(movement)

By this:

var velocity = speed*direction
velocity = move_and_slide(velocity)

Note that move and slide internally multiplies for delta, so i changed movement by velocity and avoided multiplying for delta there.

by (3,505 points)
selected by

Thank you very much! It solved my problem :))

0 votes

From what I see the only way to do this is to disable movement on collision with the wall, so that the velocity pointing to the wall goes to 0, that way the cahracter wont slow down.

by (16 points)
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.