2024-02-22 20:33:20 -05:00
|
|
|
extends CharacterBody2D
|
2024-03-04 20:35:09 -05:00
|
|
|
const speed :float = 190.0
|
|
|
|
const JUMP_VELOCITY :float = -400.0
|
|
|
|
const accel :float = 1.0071
|
|
|
|
const strength :float = 3.5
|
2024-02-22 20:33:20 -05:00
|
|
|
|
|
|
|
# Get the gravity from the project settings to be synced with RigidBody nodes.
|
|
|
|
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
|
|
|
|
|
|
|
|
var input: Vector2
|
|
|
|
|
|
|
|
func get_input():
|
|
|
|
#input.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
|
|
|
|
input.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
|
|
|
|
input.x = 1
|
|
|
|
return input.normalized()
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
|
var playerInput = get_input()
|
|
|
|
|
2024-03-04 20:35:09 -05:00
|
|
|
# Add the Gravity.
|
2024-02-22 20:33:20 -05:00
|
|
|
if not is_on_floor():
|
|
|
|
velocity.y += gravity * delta* 3
|
|
|
|
|
|
|
|
|
|
|
|
# Handle jump.
|
|
|
|
if is_on_floor():
|
|
|
|
if Input.is_action_just_pressed("ui_accept"):
|
|
|
|
velocity.y = lerp(0.0,JUMP_VELOCITY*strength, 0.93)
|
|
|
|
|
|
|
|
velocity = lerp(velocity, playerInput * speed, .01) * Vector2(accel,accel)
|
2024-02-28 20:21:50 -05:00
|
|
|
velocity.x = min(velocity.x,600)
|
2024-02-22 20:33:20 -05:00
|
|
|
|
|
|
|
|
|
|
|
move_and_slide()
|