fastRunner/player.gd

36 lines
936 B
GDScript

extends CharacterBody2D
const speed = 190.0
const JUMP_VELOCITY = -400.0
const accel = 1.0071
const strength= 3.5
# 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()
# Add the gravity.
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)
velocity.x = min(velocity.x,600)
move_and_slide()