Last active
February 17, 2018 11:01
-
-
Save LarsBergqvist/c805687485668d8869dc050505d63559 to your computer and use it in GitHub Desktop.
Godot: position a bat sprite on a random position along a PathFollow2D curve. Move with random speed and random direction.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Area2D | |
signal player_hit | |
var path = null | |
var prevX = 0 | |
var pathIdx = 0 | |
var speed = 0 | |
var direction = 0 | |
func _ready(): | |
pathIdx = randi() % 10000 | |
speed = randi() % 3 + 1 | |
direction = randi() % 2 | |
func _process(delta): | |
if position.x > prevX: | |
$AnimatedSprite.flip_h = true | |
else: | |
$AnimatedSprite.flip_h = false | |
prevX = position.x | |
if not path == null: | |
path.set_offset(pathIdx) | |
position = path.position | |
if direction == 0: | |
pathIdx += speed | |
else: | |
pathIdx -= speed | |
func _on_Bat_body_entered( body ): | |
if (not body.get("is_player") == null): | |
emit_signal("player_hit") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment