I’m currently working on a rouguelike, where I want movement similar to legend of grimrock, or the newer chocobo’s dungeon game.
I’ve tried using iTween, lerp, grid move, and moveTowards to move a test block in the dungeon, but i run into at least one of 4 problems.
- the block teleports to the area, rather than moving smoothly.
- the block doesn’t move at all
- the block move’s smoothly, but when you take your finger off the key the block stops before centering on the next tile, or goes past it slightly.
- the code doesn’t properly check for collisions
I have some code I worked on recently, using moveTowards, and I get problem 3:
using UnityEngine;
using System.Collections;
public class controllerscript : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
bool moving= false;
Vector3 endposition= transform.position+ (Vector3.forward);
if(Input.GetKey(KeyCode.W) && moving==false){
moving=true;
transform.position=Vector3.MoveTowards(transform.position, endposition , Time.deltaTime);
moving=false;
}
}
}
I’d like the cube to snap to the tiles like with typical grid movement, but so far I haven’t had any luck. Any ideas?
Thanks in advance!
The code works perfectly, even with collisions. Thanks so much :D
– sullivanshadHi .. I have an object that moves in the form of a grid, by touching it on the phone. How do I write code to move the unit left, right and forward?
– Zeohack