Remove bounciness while move_and_slide

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

As seen within the example, the player bounces back during the tree trunk collision. Due to permanent player input (against the trunk), the KinematicBody2D repeats its behaviour.

For the player I use a KinematicBody2D with following code:

var src = _movement * speed
var dest = acceleration

if src == Vector2.ZERO:
	dest = friction
if _force != Vector2.ZERO:
	_force *= (1.0 - (1.0 / friction)) * 0.9
	if _force.length() <= 0.5:
		_force = Vector2.ZERO

_velocity = move_and_slide(_velocity.move_toward(src, dest) + _force)

_force is Vector2.ZERO, as I only use it for external force input.
_movement indicates a normaized value on both axis.

Example 1
Example 2

The trunk is a part of the tilemap, whereas a collision shape (in this particular case a square) has been set up for it. I do wonder why the player bounces back, even thought the tilemap has no “surface softness” definition, nor the kinematicBody has.

reducing the acceleration from 800 to 40 fixes the issue. However, then the movements feel unnatural.

Billy the Boy | 2020-12-18 20:39