показал бы пример своего скрипта с проблемой
|
Это скрипт поворота, он у меня отрабатывает только в левую сторону, а когда нажимаю вниз или вверх объект становится повернутым вверх.
public float speed = 10.0F;
public Transform target_left; // привязываю к левой крайней стенке
public Transform target_right;// привязываю к правой крайней стенке
public Transform target_down;// привязываю к нижней крайней стенке
public Transform target_up;// привязываю к верхней крайней стенке
void Update() {
if (Input.GetKey("w"))//up
{
float step = 1800 * Time.deltaTime;
transform.rotation = Quaternion.RotateTowards(transform.rotation, target_up.rotation, step);
}
if (Input.GetKey("s"))//down
{
float step = 1800 * Time.deltaTime;
transform.rotation = Quaternion.RotateTowards(transform.rotation, target_down.rotation, step);
}
if (Input.GetKey("a"))//left
{
float step = 1800 * Time.deltaTime;
transform.rotation = Quaternion.RotateTowards(transform.rotation, target_left.rotation, step);
}
if (Input.GetKey("d"))//right
{
float step = 1800 * Time.deltaTime;
transform.rotation = Quaternion.RotateTowards(transform.rotation, target_right.rotation, step);
}
Скрипт перемещения пока отдельно.
public class Move_tank : MonoBehaviour {
public float speed = 10.0F;
void Update() {
float translation = Input.GetAxis("Vertical") * speed;
float vertranslation = Input.GetAxis("Horizontal") * speed;
vertranslation*= Time.deltaTime;
translation *= Time.deltaTime;
if (Input.GetKey("w"))//up
{
transform.Translate(0, translation, 0);
}
if (Input.GetKey("s"))//down
{
transform.Translate(0, translation, 0);
}
if (Input.GetKey("a"))//left
{
transform.Translate(vertranslation, 0, 0);
}
if (Input.GetKey("d"))//right
{
transform.Translate(vertranslation, 0, 0);
}
}
}
я пока боюсь их соединять, чтоб ошибки одного не были ошибками другого.