Deceleration doesn't seem to work

Hello everyone,

I’m making a movement system for my space game and everything works except the Deceleration as for some reason the ship hovers backward after stopping

Code:

var StopPoint = 0
var Friction = 0
var Friction_Decrease = 0.1

var direction = Input.get_axis("UP", "Down")
	if direction:
		velocity = transform.y * direction * SPEED
		StopPoint = direction
		if direction < 1 and direction > 0:
			Friction = 1
		elif direction < 0 and direction > -1:
			Friction = -1
	else :
		
		velocity = transform.y * (StopPoint * SPEED)
		if StopPoint > 0 and StopPoint < 1:
			StopPoint += (Friction - Friction_Decrease)
		elif StopPoint < 0 and StopPoint >= -1:
			
			StopPoint -= (Friction - Friction_Decrease)
		

I’m not sure what’s wrong (I’m new to GDScript so keep that in mind :sweat_smile:)

is the deceleration only handle the ship moving forward (UP)?
i tested backward, it will just keep sliding

to stop the sliding after moving forward, you add this:

if is_equal_approx(StopPoint,0):
	StopPoint=0
elif StopPoint > 0 and StopPoint < 1:
	StopPoint += (Friction - Friction_Decrease)
elif StopPoint < 0 and StopPoint >= -1:
	StopPoint -= (Friction - Friction_Decrease)
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.