using UnityEngine;
using System.Collections;
public class Snake : MonoBehaviour {
private Transform myTransform;
public int SnakeSpeed = 10;
GameObject Snakei;
// Use this for initialization
void Start () {
myTransform = transform;
}
// Update is called once per frame
void Update () {
myTransform.Translate(Vector3.right * SnakeSpeed * Input.GetAxis("Horizontal")* Time.deltaTime);
myTransform.Translate(Vector3.up * SnakeSpeed * Input.GetAxis("Vertical")* Time.deltaTime);
}
void OnTriggerEnter(Collider coll)
{
if(coll.gameObject.CompareTag ("Maze"))
{
Destroy (this.gameObject);
}
}
}
It successfully moves but without any continuos motion…any help would be appreciated
I would go about it by storing the control in a variable.
Pseudocode:
Update(){
If ( control direction is true){ then apply force/translate)
}
//You’ll need a variable to store the last direction, like this:
private Vector3 lastDirection = Vector3.up;
//This controls how "touchy" your controls are
private float threshold = 0.25f;
//In the update loop, you look to see if you need to change it.
public void Update(){
//Get the current keypresses as a Vector3.
Vector3 inputDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
//See if they amount to a key being pressed by checking the "magnitude" which is sort of like the length of the line it would create.
Vector3 desiredDirection = this.lastDirection; //Start by assuming we're continuing the same way as last time
if(inputDirection.sqrMagnitude > threshold) //Unless the player gives us a new direction
{
desiredDirection = inputDirection;
this.lastDirection = desiredDirecton;
}
//Now continue all your movement code, but use desiredDirection instead of the other inputs.
}