- Home /
Moving a gameobject towards another
Hi guys,
Im starting a new project which is a 3d board game and I want to make it so that when I click a tile my character would move to it.
I could transform.position but it would just appear and I would like to see the character move towards the tile.
Ive tried to experiment with itween but im hopeless. I just want to get the basic mechanics down first before I make it look pretty.
What would be the best way of making clicking a tile and making, player 1 for example, move towards it.
Thanks
Answer by save · Sep 05, 2012 at 03:43 PM
Vector3.MoveTowards or Vector3.Lerp. The idea is that you set a target position as a Vector3 and over time move current position X, Y and Z towards the target X, Y and Z. To get a clicked position depending on your tiles, either get the transform.position of your tile or round the clicked position to get a grid position at the center of the graphical presentation of the tile.
Cheers, Ill have a look into it. Im not a programmer so I struggle when it comes to these.
So will I have to make a currentPlayerLocation variable for the character and tileLocation to make transform.position = Vector3.Lerp(currentPlayerLocation, tileLocation, 2) ?
Not quite. Re-read the docs for Lerp. The third argument will be a value that progressively changes from 0 to 1.. 0 will return the start position, and 1 will return the final position.
Your answer
Follow this Question
Related Questions
Move window game 0 Answers
Unity: C#: Eyes look at mouse: HELP!! 3 Answers
Isometric/Dimetric 2D game with pixel art tiles 0 Answers