Base version of game
This commit is contained in:
24
Player.gd
Normal file
24
Player.gd
Normal file
@@ -0,0 +1,24 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
const ACCELERATION = 1000
|
||||
const MAX_SPEED = 120
|
||||
const FRICTION = 1000
|
||||
|
||||
var velocity: Vector2 = Vector2.ZERO
|
||||
|
||||
|
||||
func _physics_process(delta) -> void:
|
||||
var input_vector: Vector2 = Vector2.ZERO
|
||||
|
||||
input_vector.x = Input.get_action_strength('player_right') - Input.get_action_strength('player_left')
|
||||
input_vector.y = Input.get_action_strength('player_down') - Input.get_action_strength('player_up')
|
||||
input_vector = input_vector.normalized()
|
||||
|
||||
if input_vector != Vector2.ZERO:
|
||||
$AnimationTree.set('parameters/Idle/blend_position', input_vector)
|
||||
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
|
||||
else:
|
||||
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
|
||||
|
||||
velocity = move_and_slide(velocity)
|
||||
return
|
Reference in New Issue
Block a user