[Solved]My Friction wont work

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

Hi Guys,
First, sorry for my Bad English.
Im new on Godot, and i try to move my Character Smooth, but, it wont work, and i dont understand why.

Hope you can help me!

Heres the Code:

var pSpeed = 180
var pJumpspeed = -180
var pGravity = 400
var pState = "Idle"
var pDir = 1
var pVelocity = Vector2()
var pFriction = 0.25
var pAcceleration = 0.5

func get_input():
	pVelocity.x = 0
	if pState == "Idle":
		if Input.is_action_pressed("kRight"):
			pDir = 1
			pState = "Walk"
		if Input.is_action_pressed("kLeft"):
			pDir = -1
			pState = "Walk"
	if pState == "Walk":
		if Input.is_action_pressed("kRight"):
			pDir = 1
		if Input.is_action_pressed("kLeft"):
			pDir = -1
		if !Input.is_action_pressed("kRight") and !Input.is_action_pressed("kLeft"):
			pState = "Idle"

func get_speed():
	if pState == "Walk":
		pVelocity.x = lerp(pVelocity.x, pDir * pSpeed, pAcceleration)
	if pState == "Idle":
		pVelocity.x = lerp(pVelocity.x, 0, pFriction)

func _physics_process(delta):
	pVelocity.y += pGravity * delta
	pVelocity = move_and_slide(pVelocity, Vector2.UP)
:bust_in_silhouette: Reply From: exuin

It looks like you set pVelocity to zero every frame, so when you apply friction it won’t work since velocity is already 0.

Thank you. That’s exactly it, I don’t know how I could have missed it.

CreepyDeath | 2021-02-24 23:39