Hey guys! 
I’m making a card game in Unity, and I’ve met a slight problem.
The relevant code from my program is:
public void Update()
{
speed = 350f;
attacker.position = Vector3.MoveTowards(attacker.position,
target, speed * Time.deltaTime);
}
With this code my computer moves his cards towards mine and start combat when attacker.position equals target.position.
When this code was only moving normal cards toward mine, everything was okay. But later on, when I tried to move opponent’s hero towards my cards, the code bugged. The console doesn’t notice any error, but something strange happens. The opponents hero just start shaking. After little investigation I figured out, that hero tries to move toward my card, but after 1 frame, he just resets his position and tries to move again and reset and end up shaking.
I’m wondering what may I wrote wrong, because this code works well for other cards, just hero resets his position. Am I doing anything wrong in “Inspector screen” maybe? I don’t allow to move hero?
Any suggestions and/or help would be greatly appreciated 
Thanks for your time!
in order for the position to be reset there has to be a script telling it to do that. Somewhere in your scene is a script that is also updating the hero’s position…
And this code should be in update function probably? Else it wouldn’t reset his position every frame? I’ll look if I have misswrote this somewhere, but chances are low…
… is the hero animated? you might also have baked the world position (or the local position to another object) into the keyframes?
Well, it’s not animated. It’s just an image. Everything is 2D at the moment and I no animations are included aside this moving. I’m using one big canvas for entire battle screen, and then few small canvases to present battle zones. Let’s say, cards I was moving before were in one canvas named “battlefield”. The hero is inside his own canvas, named let’s say “heroZone”. I’m pretty sure I’m not reseting his position via code. Maybe the “heroZone” somehow doesn’t allow him to move outside of it?
should be letting it, you can have children with offsets that set them to be well outside the bounds of the parent rectTransform. Only thing I can think of that would cause “problems” there would be a mask which would make the child disappear when it goes outside the parent’s bounds.
Children being outside the parent bounds is pretty much required for the ScrollLists and Mask to function usefully so i’d say it’s not likely to be that.
If it helps, here is how the object is moving (<-- Link)
public void Update()
{
speed = 350f;
Debug.Log(attacker.position);
attacker.position = Vector3.MoveTowards(attacker.position,
target, speed * Time.deltaTime);
Debug.Log(attacker.position);
}
It moves a bit in the direction, next frame a bit more, and then a little bit further and jumps back. And repeats. Seems when he goes for 15 units outside, he jumps back. It’s not like he resets his position every frame.
Any ideas?
Woah, I actually managed to fix it. Before moving, I set his parent to the big canvas and after moving set his parent back to “heroZone”. Now he moves, fights and everything like he should. No idea what was wrong before, but now it works. Thanks for help anyway Lefty <3