I’m doing a pan movement with the middle mouse click.
I’ve got a camera wich rotate around a target linked by the rotate script.
At the moment I tried that
public class Pan : MonoBehaviour {
public Transform Target;
public float Sensitivity;
private float MoveX;
private float MoveY;
// Update is called once per frame
void Update () {
if (Input.GetMouseButton(2))
{
MoveX += Input.GetAxis("Mouse X") * Sensitivity;
MoveY -= Input.GetAxis("Mouse Y") * Sensitivity;
}
Target.position = new Vector3(MoveX, 0, MoveY);
}
}
Obviously the pan movement is always in the same direction, so basicaly now I need to connect it with the direction of the camera, do someone has an idea for that ?
I’ll continue to post my researches an problems here.
it doesn’t work (the target doesn’t rotate at all.
if i’m using this line instead
Target.rotation = Camera.rotation;
The cube as the same rotation as my camera and the pan works better but I only need the Y rotation not the others otherwise when I pan forward i go through the ground the target can only move on 2D. And bigger problem, now when I’m rotating the cam with left click, the cube move slightly.
So I need to constraint my target Y rotation to the Camera Y rotation and then move in the right direction.