I have a artillery-type model in my game, and i want one group of pieces to rotate left and right to look at the player, and a group inside that group to also rotate up and down to point at the player. I have a script made, but it won’t let me pick the right direction to be forward.
using UnityEngine;
using System.Collections;
public class Aim : MonoBehaviour {
public Vector3 LeftRightForward;
public Vector3 UpDownForward;
public bool LeftRight;
public bool UpDown;
GameObject Player;
void Start()
{
Player = GameObject.Find("Player");
}
void Update()
{
if (LeftRight)
{
GetComponent<Rigidbody>().rotation = Quaternion.LookRotation(new Vector3(Player.transform.position.x, transform.position.y, Player.transform.position.z) - transform.position, LeftRightForward);
}
if (UpDown)
{
GetComponent<Rigidbody>().rotation = Quaternion.LookRotation(Player.transform.position - transform.position, UpDownForward);
}
}
}
(The reason for so many public variables is so i could find out which direction was the right forward for the model from the editor.)
Here are pictures of the model:
Does anyone know what is wrong?
P.S. The Up-Down and Left-Right have the script attached with the correct bool set to true. These pictures are slightly old