This repository has been archived on 2024-02-25. You can view files and clone it, but cannot push or open issues or pull requests.
NotionGodot/Player.gd

36 lines
698 B
GDScript3
Raw Permalink Normal View History

2020-08-12 14:05:48 +02:00
extends KinematicBody2D
export var movement_speed = 100
export var jumping_enabled = false
var gravity = 0
var direction = Vector2.ZERO
var jump_strength = 50
func _ready():
pass
func _input(event):
if event is InputEventKey:
if event.pressed:
match event.scancode:
KEY_A:
direction.x = -1
KEY_D:
direction.x = 1
KEY_SPACE:
if is_on_floor() and jumping_enabled:
gravity = -9.81 * jump_strength
else:
if [KEY_A, KEY_D].has(event.scancode):
direction = Vector2.ZERO
func _physics_process(delta):
gravity += 9.81 * 100 * delta
move_and_slide(Vector2(direction.x * movement_speed, gravity), Vector2(0, -1))
if is_on_floor():
gravity = 0