This must be very basic thing to do but I can't figure it out. I'm trying to move things in a grid layout when user uses movement keys. I've got everything else figured out but I can't figure out how to actually move the thing. How can I animate the movement of 1 unit to about 0.5 seconds? If I use transform.position it move there, yes, but in one frame. It should also block moving it again before the new position has been reached so move commands won't stack up 60 times a second.
Another thing. This is a rpg style game, like the pokemon on handhelds. Should I use tiles for the maps or what? If I use tiles the hierarchy is full of them (think 300 x 300 map, so 9000 tiles) and I suspect it'll lag the game. How should I construct the terrain?
asked Jan 08 '10 at 01:46 PM
i made a script that can help you. i never used it in my project but i think you can use it now basicaly in these situations you should use coroutines. if you want to move something 16 meter in a second you should add 16*time.deltaTime to it each frame.
public class move : MonoBehaviour
} the important function is MoveInGrid that takes values as target position in world space and move the gameobject to there. see my Update function to learn it's usage. i used local positions in my Update function. the script's gridsize is equal in x,y,z and you can set this size and speed inside inspector. the component is completely reusable but you can modify it or only use MoveInGrid coroutine.
I've put a grid movement script on the wiki here: http://www.unifycommunity.com/wiki/index.php?title=GridMove
I'm afraid the other script has some issues, such as being wayyyy too long ;), repeating the same transform.position twice on "grid lines" (leading to slight but visible hiccups when traversing more than one square in a row), and sometimes moving two squares at once.
As far as the maps go, they should be done using a single plane, where each square is an individually UV mapped tile, using a texture atlas. Using separate objects for each tile is a recipe for massively worse performance.
answered Jan 15 '10 at 09:12 AM