ajout accéleration
This commit is contained in:
parent
39e34e9be1
commit
048bb09ab7
4 changed files with 126 additions and 2 deletions
|
@ -1,6 +1,12 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
const move_speed = 400
|
||||
const acceleration = 0.25
|
||||
const max_boost_speed = 800
|
||||
|
||||
var previous_direction = Vector2.ZERO
|
||||
var boost_speed = 0
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
move_and_slide()
|
||||
|
@ -10,6 +16,13 @@ func _process(delta: float) -> void:
|
|||
direction.x = Input.get_action_raw_strength("BOUGER_DROITE") - Input.get_action_raw_strength("BOUGER_GAUCHE")
|
||||
direction.y = Input.get_action_raw_strength("BOUGER_BAS") - Input.get_action_raw_strength("BOUGER_HAUT")
|
||||
|
||||
velocity = direction * move_speed
|
||||
|
||||
|
||||
if direction != Vector2.ZERO:
|
||||
if direction == previous_direction:
|
||||
boost_speed = min(boost_speed + acceleration, max_boost_speed - move_speed)
|
||||
else:
|
||||
boost_speed = 0
|
||||
previous_direction = direction
|
||||
velocity = direction * (move_speed + boost_speed)
|
||||
print(velocity)
|
||||
pass
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue