Skip to content

Instantly share code, notes, and snippets.

@ACatThatPrograms
Last active March 7, 2019 16:15
Show Gist options
  • Save ACatThatPrograms/05b76ba6de12a2ef4bd9424eb48d4347 to your computer and use it in GitHub Desktop.
Save ACatThatPrograms/05b76ba6de12a2ef4bd9424eb48d4347 to your computer and use it in GitHub Desktop.
Written in GDScript :: First function tracks movement direction as a vector and entity facing direction of follower entities that trail behind the player for classic JRPG like caching of last-player-positions within an array for utilizing within the follower entities for movement : The second function is using this array and providing a unique e…
func check_trail_cache():
if player_last_pos != player.position:
position = player_trail[0][0]
move_dir = player_trail[0][1]
if position_index < frame_offset:
position_index += 1
else:
position_index = 0
if player_trail.size() > frame_offset:
player_trail.pop_front()
player_trail.push_back([player.position, player.move_dir])
last_pos = position
else:
move_dir = Vector2(0,0)
player_last_pos = player.position
func follower_check_trail():
if player_last_pos != get_tree().get_nodes_in_group("party")[0].leader.position:
position = player_trail[0+position_offset][0]
move_dir = player_trail[0+position_offset][1]
player_trail.push_front([get_tree().get_nodes_in_group("party")[0].leader.position, get_tree().get_nodes_in_group("party")[0].leader.move_dir])
else:
move_dir = Vector2(0,0)
player_last_pos = get_tree().get_nodes_in_group("party")[0].leader.position
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment