May i have some help discovering how to stop friction on walls?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rothbird

I’m new at learning godot and i really need help with this :confused:

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 _physics_process(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)
:bust_in_silhouette: Reply From: BlagoySimandov

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.

:bust_in_silhouette: Reply From: p7f

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.

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

rothbird | 2020-07-26 01:29