Hi everyone!
Im making a game similar to geometry wars.
I have a ship asset, and what I want to do is that this asset to rotate acorrdly to the mouse position(for targeting enemies).
Im going mad to solve this issue, I cant figure out how it is donde.
I´ve tried so far assigning the asset rotation to the mouse position, and also intantiatin a invisible dummy where the mouse is and using the lookAt() method. But none of these aproaches work.
can you post the script you used (if you still have it)
I can see if we can do something like locking the axis of the instantiated dummy to the same plane as the player.
public var object : Transform; //Dummy object goes here
function LateUpdate () {
var ray = camera.ScreenPointToRay (Input.mousePosition);
Debug.DrawRay (ray.origin, ray.direction * 20, Color.red);
var target = ray.GetPoint(-ray.origin.y / ray.direction.y);
object.transform.position = target;
}
this should work for a top down view just attatch it to the camera its not complete but if you place a debug object (sphere) into the slot in the camera’s Inspector window it will follow the mouse along the Y axis at 0
Placing an emtpy game object In the inspector is your object for the gun to track.
Howso? this was the only way i could achieve the desired results.
oh yeah and can anybody here tell me how to rotate towards the mouse position on the verticle plane without the the object fliping over at certain angles
this is driving me IN-FUCKIN-SANE. :evil:
The transform.LookAt function has an optional second parameter that specifies the upward direction of object. This defaults to the Y axis - the flipping occurs if the upward direction and the direction you’re looking at get too close together. The solution is to pass the axis of rotation as the upward direction (this will probably be equal to -Vector3.forward if I understand what you’re doing correctly):-