Skip to content

Instantly share code, notes, and snippets.

@LarsBergqvist
Last active February 17, 2018 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LarsBergqvist/c805687485668d8869dc050505d63559 to your computer and use it in GitHub Desktop.
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.
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