20 lines
438 B
GDScript
20 lines
438 B
GDScript
extends KinematicBody2D
|
|
|
|
const GRAVITY = 2000.0
|
|
const SNAP = Vector2(0, 100)
|
|
var velocity = Vector2(0, 0)
|
|
var snap = SNAP
|
|
export var health : int = 100
|
|
|
|
func _process_gravity(delta):
|
|
if not is_on_floor():
|
|
velocity.y += delta * GRAVITY
|
|
else:
|
|
velocity.y = 1
|
|
if is_on_ceiling():
|
|
velocity.y = 1
|
|
|
|
func _physics_process(delta):
|
|
if velocity != null:
|
|
move_and_slide_with_snap(velocity, snap, Vector2(0, -1))
|
|
_process_gravity(delta)
|