- Home /
Question by
eddieion · Apr 29, 2016 at 06:27 AM ·
movementgrid based game
Grid-based movement *without* smooth movement between tiles?
Hey all,
I'm trying to create some very basic cellular automata but don't want smooth movement when different cells (referred to as photons in my script) move from grid position to grid position.
I'm not quite sure how to achieve this? Script below that controls moment.
using UnityEngine;
using System.Collections;
public class MovingObject : MonoBehaviour {
public GameObject Photon;
Vector3 pos; // For movement
float speed = 10f; // Speed of movement
// Use this for initialization
void Start () {
pos = transform.position; // Take the initial position
}
// Update is called once per frame
void FixedUpdate () {
if(Input.GetKey("space") && transform.position == pos) { // Down
pos += Vector3.down;
}
transform.position = Vector3.MoveTowards(transform.position, pos, Time.deltaTime * speed); // Move there
}
}
Comment