I’ve been working on this problem for the last 2 hours, but even if the solution seems really easy I couldn’t get it working.
here is my problem;
I have a 2d arm object rotated by the mouse and it shoots bullets when left mouse button is pressed. Rotation of the arm works fine, but whenever I try to shoot, the angle of the bullets are slightly off. The direction where they going is fine only the local rotation of the bullets are wrong. I tried to change its local rotation by using transform.localRotation, but this time it completely broke the shooting direction.
Also its not related but even though the code I’m using for rotating the Arm is working fine, I’m using a really huge number(-5000) in z axis to get it working. Has anyone know the correct solution for this problem?
Here is the code for the Arm object;
#pragma strict
var bullet : Transform;
var cameraDif : int;
function Update()
{
transform.LookAt(Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y,
-5000)), Vector3.forward);
transform.eulerAngles.z-=90;
if(Input.GetMouseButtonDown(0))
{
var mytransform : Vector3;
mytransform.x=transform.position.x;
mytransform.y=transform.position.y;
mytransform.z=0;
Instantiate(bullet,mytransform,transform.rotation);
}
}
Thank you