rotation based on mouse position

OK, so what im working on is a basic dog fighter like game. I wan the object to face the crosshairs at all times (set to mouse position in another script) i thought the best way to do this was to set the rotation based on the mouse position as well but i cant seem to get the calculations for the rotation right because it calls the left side of the screen 0 not the center. Can someone set me on the right path?

here is my code idk if you’ll need it or if it will even help,

#pragma strict

//move variables
var leftThrust: ParticleSystem;
var rightThrust: ParticleSystem;
var centerThrust: ParticleSystem;
var speed: float=1;
var turn: float=1;
//rotate variables
var mouse_pos: Vector3;
var obeject_pos: Vector3;
var target: Transform;
var angle: float;
function Start () {

}

function Update () 
{
	BasicMovement ();//begins on line 27
	Turning ();// begins on line 88
}

function BasicMovement ()//basic movement Input
{
	//zero out
	if (Input.GetAxis("Horizontal")==0)
	{
		leftThrust.particleSystem.enableEmission=false;
		rightThrust.particleSystem.enableEmission=false;
	}
	if (Input.GetAxis("Vertical")==0)
	{
		centerThrust.particleSystem.enableEmission=false;
	}
	if (Input.GetAxis("Horizontal")==0 && Input.GetAxis("Vertical")==0 )
	{
      rightThrust.particleSystem.enableEmission=false;
      centerThrust.particleSystem.enableEmission=false;
	}
	//going left
	if (Input.GetAxis("Horizontal")<0)
	{
      rightThrust.particleSystem.enableEmission=true;
      transform.Rotate(0,0,-turn);
	}
	if (Input.GetAxis("Horizontal")<0 &&Input.GetAxis("Vertical")>0 )
	{
      rightThrust.particleSystem.enableEmission=true;
      centerThrust.particleSystem.enableEmission=true;
	}
	//going Right
	if (Input.GetAxis("Horizontal")>0)
	{
      leftThrust.particleSystem.enableEmission=true;
      transform.Rotate(0,0,turn);
  	}
  	if (Input.GetAxis("Horizontal")<0 &&Input.GetAxis("Vertical")>0)
	{
      rightThrust.particleSystem.enableEmission=true;
      centerThrust.particleSystem.enableEmission=true;
    }
  	//going foward
  	if (Input.GetAxis("Vertical")>0)
	{
		centerThrust.particleSystem.enableEmission=true;
		transform.Translate(-speed, 0, Time.deltaTime);
	}
	//going back
	if (Input.GetAxis("Vertical")<0)
	{
		centerThrust.particleSystem.enableEmission=false;
		transform.Translate(speed, 0, Time.deltaTime);
	}
	//going Up
	if (Input.GetAxis("Jump")>0)
	{
		transform.Translate(0, Time.deltaTime,speed);
	}
	//going Down
	if (Input.GetAxis("Jump")<0)
	{
		transform.Translate(0, Time.deltaTime,-speed);
	}
}

function Turning ()
{
	var angleX: float;
	mouse_pos = Input.mousePosition;
	mouse_pos.x = mouse_pos.x - obeject_pos.x;
	mouse_pos.y = mouse_pos.y - obeject_pos.y;
	angle = Mathf.Atan2( mouse_pos.y, mouse_pos.x)* Mathf.Rad2Deg;
	angleX = angle + 90;
	if ( angle < 90 && angle > -90)
	{
		transform.rotation=Quaternion.Euler(Vector2(-angleX,0));
	}
}

That’s some complicated trigonometry you’re doing there, and I’m not quite sure what it does.
The screen’s center you can get by using a Vector2 screenCenter = new Vector2(Screen.width / 2, Screen.height / 2);

Also, here’s some simpler code that could probably help you out; it’s what I’m using to control my spaceship.

public float rotationSpeed = 60.0f;

// Rotation around the Euler angles
float pitch = -Input.GetAxis("Mouse Y") * rotationSpeed * Time.deltaTime;
float yaw = Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime;
float roll = -Input.GetAxis("Mouse X") * rotationSpeed * Time.deltaTime;
Vector3 rotation = new Vector3(pitch, yaw, roll);
rotation = Vector3.Lerp (Vector3.zero, rotation, Time.deltaTime * rotationSpeed); // Smooth...
// PHYSICS - nah
//Vector3 rotation = new Vector3(roll, yaw, pitch); // rigidbody rotation wants the angles in a different order...?
//transform.rigidbody.AddTorque(rotation);
transform.Rotate(rotation);

I’m achieving nice, smooth rotation around all Euler angles easily. Adding torque didn’t really work, because it made the player compensate for the force by adding a counter-force in the opposite direction, and that never was too much of a nuisance to deal with, but it’s also a way to do it if you so desire.

I hope this helps!

The code that initialized ‘obeject_pos’ is not here, but I’m going to assume it is set to a coordinate in world space. I’m guessing that it is transform.position. The issue you have is that Input.mousePosition is a Screen coordinate and your object lives in world coordinates. Before you can get the angle, you have to either convert the mouse to world coordinates, or convert the world coordinate to screen coordinates:

var v3 = Camera.main.WorldToScreenPoint(object.pos);

As for your turning code, I’m not sure what is going on since you are rotating around the ‘X’ axis. I’d need to know more about your camera setup and why the ‘X’ axis before I can verify the code. But the above line should get your calculations in the same coordinate system.