Topic was automatically imported from the old Question2Answer platform.
Asked By
greencloversguy
I have a character in my game who moves on a grid, and I am handling their movement through animations. I would like to set it up so, when they are halfway through moving, their current tile changes. So for example, if my player moves out of a tile after an enemy attacks the tile, the enemy will miss.
I currently have this code:
func move_to_tile(vec):
var temp = currenttile + vec
if !(temp.x < tl.x or temp.y < tl.y or temp.x > br.x or temp.y > br.y):
for anim in anims:
if (vec == anim["pos"]):
$AnimationPlayer.play(anim["name"])
yield($AnimationPlayer,"animation_finished")
currenttile = temp
position = $Sprite.position + position
$Sprite.position = Vector2.ZERO
emit_signal("player_moved", currenttile)
So currently, my code starts playing the animation, waits for it to finish and then resolves the position of the character. What I would like for it to do is the same, but do it when the animation is halfway completed. Is there a way I can do this somewhat easily within the code? Can I add some code to the Animation Player and create a new signal easily? Or would I be better off splitting my move animations into seperate animations? For example, make 2 seperate “Move a tile right” animations.
My current setup has me creating the animations in the code before the game starts. I’m struggling to find a good reference to use to help me add in a method track. I have the following in my code:
E 0:00:02:0772 Condition ' p_key.get_type() != Variant::DICTIONARY ' is true.
I assume that this is because the key I’m trying to add needs to be a dictionary, but I can’t find what the dictionary I need to make looks like,what values it needs. Any help?
greencloversguy | 2019-08-01 08:05
Found it in the source code. For future coders, dictionary needs to look like the following: