virtualx-engine/demos/2d/fog_of_war/troll.gd

40 lines
1,003 B
GDScript3
Raw Normal View History

2015-02-02 23:08:57 +01:00
extends KinematicBody2D
# This is a simple collision demo showing how
# the kinematic controller works.
2015-02-02 23:08:57 +01:00
# move() will allow to move the node, and will
# always move it to a non-colliding spot,
2015-02-02 23:08:57 +01:00
# as long as it starts from a non-colliding spot too.
# Member variables
const MOTION_SPEED = 160 # Pixels/second
2015-02-02 23:08:57 +01:00
func _fixed_process(delta):
var motion = Vector2()
if (Input.is_action_pressed("move_up")):
motion += Vector2(0, -1)
2015-02-02 23:08:57 +01:00
if (Input.is_action_pressed("move_bottom")):
motion += Vector2(0, 1)
2015-02-02 23:08:57 +01:00
if (Input.is_action_pressed("move_left")):
motion += Vector2(-1, 0)
2015-02-02 23:08:57 +01:00
if (Input.is_action_pressed("move_right")):
motion += Vector2(1, 0)
2015-02-02 23:08:57 +01:00
motion = motion.normalized()*MOTION_SPEED*delta
2015-02-02 23:08:57 +01:00
motion = move(motion)
# Make character slide nicely through the world
2015-02-02 23:08:57 +01:00
var slide_attempts = 4
while(is_colliding() and slide_attempts > 0):
2015-02-02 23:08:57 +01:00
motion = get_collision_normal().slide(motion)
motion = move(motion)
slide_attempts -= 1
2015-02-02 23:08:57 +01:00
func _ready():
# Initalization here
set_fixed_process(true)