Making a Good platforms game 2d controller

Hello,
Im triying to make a good sensing player controller for a 2d platformer, but I can’t find a way of making it feel smooth. For the moment, this is my code:

Current code (GDScript)
``````extends CharacterBody2D

var Gravity:float = ProjectSettings.get("physics/2d/default_gravity")*1.2
@export var HAcel := 950
@export var HMaxSpeed := 300
@export var JumpForce := 450
@export var CoyoteTime := 0.15
var RoundToStopFloor := HAcel*0.3
var RoundToStopAir := HAcel*0.1

enum MoveStates{
Walk,
Jump
}
var CurrentMoveState:int = MoveStates.Walk

func _physics_process(delta):
velocity.y += Gravity*delta
if velocity.y >0: #This will make the fallling faster (I read somewhere that it makes the movement feel better)
velocity.y += Gravity*delta
velocity.y = min(500, velocity.y)
var HMovement = Input.get_axis("game_left", "game_rigth")
var IsOnFloor := is_on_floor()
if HMovement>0:
\$Sprite2D.flip_h = false
elif HMovement<0:
\$Sprite2D.flip_h = true
if HMovement*velocity.x<0: #Change run orientation
velocity.x = -velocity.x
velocity.x = lerp(velocity.x, 0.0, 0.5)
if abs(velocity.x) <HMaxSpeed and HMovement != 0: #Increase velocity
velocity.x += HAcel*delta*HMovement
elif HMovement == 0 and abs(velocity.x)>RoundToStopFloor and IsOnFloor: #Decrease velocity in floor
velocity.x += HAcel*delta*(-velocity.x/abs(velocity.x))
elif abs(velocity.x) <=RoundToStopFloor and IsOnFloor: #Truncate velocity on earth
velocity.x = 0
elif  abs(velocity.x) <=RoundToStopAir and not IsOnFloor:
velocity.x = 0
if Input.is_action_just_pressed("Jump") and CoyoteTimer.time_left>0:
CurrentMoveState = MoveStates.Jump
velocity.y = -JumpForce
if IsOnFloor:
CoyoteTimer.wait_time = CoyoteTime
CoyoteTimer.start()
move_and_slide()
``````

With this code, the player jumps and walk feels weird and I don’t know what to do to fix it and make it feel good (A good platforms game).
Do anyone know how to make it feel good?
Thanks

1 Like

This is pretty harsh

This threshold could be too high for setting velocity to zero. Maybe you should get rid of this and add extra friction if there is no movement direction.

1 Like

O tried a lot of values and that is the one which matchs better. I think that the problem is more in the jump.

1 Like

About, that. In the next line I keep it to the half of it so I think that there is not problem.

I had the same problem some time ago. In my opinion there is no magic configuration. First you have to question yourself what kind of platformer you intend to build. I looked about a lot about the controls of Celeste and hollow knight to get an understanding how they made it so crisp.

Basically it depends how platforming or combat heavy your game should get. E.g. Celestes can’t jump very high and falls very fast. which gives a precise control that is needed for the game.

also you need to adjust the jump height to your map tiles.

Technics like Coyote timer which you are already using are also important to keep the players frustration lower for less precise inputs ^^

I think this was the video that helped me out the most. Dont be afraid by the “unity” in the title in my opinion this is just the example to express certain concepts of different platformers. its not like a full coding guide ^^

I hope this answer helps you progressing

1 Like

Ok, Thanks!

1 Like

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