Move in direction

Hi. I ’ ve implemented movement in a mobile game. When you touch in floor (is a top down 2d game), the player goes to position using your fantastic plugin. All is ok. Now I want a new functionality.
Let me explain: if you leave your finger touching the right part of the screen, I want the player to move towards your finger As the screen moves, and the player is always in the middle of it, it will always walk until you stop touching the screen. It simulates a touch pad.
My doubt is to know what is the best approach to do it in terms of performance. I know I can be capturing the position of the finger each 300ms (i.e.), and recalculating the path of the seeker all the time, but I do not know if this will not be too heavy.

Thank you in advance!

Hi

If you use one of the included movement scripts then you can simply every frame set

ai.destination = fingerPosition;

The AI will recalculate its path at regular intervals depending on the ‘repath rate’ variable. Even on a smartphone, if you just have one or a few characters, recalculating the path multiple times per second shouldn’t be a problem at all, especially since the paths will usually be very short in this case.

if your using a gameobject as your target, you can set its position and to be a child of the camera, so the targets position will always be offset as the camera moves. then have a pointerup event that removes the child and it will no longer be offsetting the value.

Thanks a lot of. I’ve resolved calling repath every 300 miliseconds when finger is touching screen, and all is ok.

1 Like