- Home /
Move object and remove path
Hi everyone I'm new so this might be a very dumb question but I am trying to recreate this effect .
I have an object which Is a filled triangle(player). I want it to move to the outlined triangle(target) along the path defined by a white line so that it moves and stops when it is at the center of the outline.
I am using two sprites here . One being a triangle (for the filled triangle) and the other being an outline ( for the triangle with no fill). I have set the player to move to the target when it is tapped for this I am using transform.translate.
Now the issue is that the filled triangle does not enter the outline as it just collides and stops moving. and I am unable to implement a path effect. I am unable to show a line which indicates the path the player will follow to get to the target. And I have no idea how I will erase the line as the player moves along .
All help is appreciated. Thanks.
Answer by Akadeax · Nov 04, 2018 at 12:05 PM
Well, to move the object you could use Vector2.MoveTowards. In case you need syntax:
transform.position = Vector2.MoveTowards(transform.position, target.position, speed);
And for the path? I guess you could use a line renderer to show a path between the current position and the target.
(oh, and put the collider of the outline to trigger, if you meant that).