So I am following Heart Beast's action RPG series, and I've noticed an issue. When my player collides with my bushes, the player sometimes sticks to it if I'm moving diagonally into the curved side of the bush, and sometimes the character "bounces" off the bush mush faster than normal. I don't know how long it has been present, but I don't know how to fix it.
Below is the code and a video of the issue:
extends KinematicBody2D
const max_Speed = 100
const acceleration = 500
const friction = 500
enum {
move,
roll,
attack
}
var state = move
var velocity = Vector2.ZERO
var roll_vector = Vector2.DOWN
onready var animationPlayer = $AnimationPlayer
onready var animationTree = $AnimationTree
onready var animationState = animationTree.get("parameters/playback")
func _ready():
animationTree.active = true
func _physics_process(delta):
match state:
move:
move_state(delta)
roll:
roll_state(delta)
attack:
attack_state(delta)
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()
roll_vector = input_vector
if input_vector != Vector2.ZERO:
animationTree.set("parameters/Idle/blend_position", input_vector)
animationTree.set("parameters/Run/blend_position", input_vector)
animationTree.set("parameters/Attack/blend_position", input_vector)
animationTree.set("parameters/Roll/blend_position", input_vector)
animationState.travel("Run")
velocity = velocity.move_toward(input_vector * max_Speed, acceleration * delta)
else:
animationState.travel("Idle")
velocity = velocity.move_toward(Vector2.ZERO, friction * delta)
move()
if Input.is_action_just_pressed("attack"):
state = attack
if Input.is_action_just_pressed("roll"):
state = roll
func attack_state(delta):
velocity = Vector2.ZERO
animationState.travel("Attack")
func roll_state(delta):
animationState.travel("Roll")
velocity = roll_vector * max_Speed * 1.5
move()
func move():
velocity = move_and_slide(velocity)
func roll_animation_finished():
velocity = velocity * 0.75
state = move
func attack_animation_finished():
state = move
Here is a link to a video of the problem