Hi
I would like to know how i would put this in java. I want my turret to turn around and follow my mouse. Thanks
i apreciate the help.
The most straightforward solution would probably be to use the quaternion ‘LookRotation’ function to ‘point’ the turret at the current mouse position. (The details will depend on how you have things set up in your project.)
ok thanks i’ll look it up
ok so i found this :
// transform.LookAt instead
var target : Transform;
function Update ()
{
var relativePos = target.position - transform.position;
var rotation = Quaternion.LookRotation(relativePos);
transform.rotation = rotation;
}
but how would i point my target to my mouse since it isnt realy an object
You’ll most likely need to build a Vector3 object representing the mouse position, and then subtract from it the turret position. You can then use the result as the argument to LookRotation().
Note that the mouse and turret positions will need to be in the same space in order for this to work.