A simple look fucntion

First off, thanks to Robertu for helping me out with the last answers. So appreciated.

So I have an object that acts to aim fireballs when a controller is selected. It’s just a little capsule that uses rotateAround() to point the aim point of the spawnPOint.
Currently fireballs aim toward the mouse, using a spawn point selected based on whether or not the mouse is left or right of the character.
I’d prefer to use the aiming apparatus for mouse aiming as well. it’s so much nicer looking and effective than my current mouse aiming.

What I can’t figure out is how to set the angle for rotateAround(point at the mouse);

I already have my adjust mouse co-ordinates from raycasting to the world from camera and all that jazz.
Now if someone can please help me understand how to toss in the co-ordiantes of the mouse to rotateAround that would be fantastic.

So, expected bahavior is the aimingArm with rotateAround the character rotateAround(this.Tranform,x) where x is the angle to point at the mouse.

Current behavior is non-existant. :frowning:

I tried to look at a dozen or so examples on how to use lookat to point a quat., but lookAt doesn’t hold water with application that I can see. Thus I am confused and need assistance.
Thanks guys.

From your description, I’m assuming this is 2D and orthographic, and that you are rotating 360, not flipping. First, edit your sprite so that the forward side is facing right when the rotation is (0,0,0). Then you can do:

 var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
 var dir = transform.position - worldMousePosition;
 var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
 transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

It’s actually built on 3d, perspective locked.


During play the view is essentially locked to the z, so that movement is on the x/y save certain circumstances.
I have the mouse adjusted for this though, so it can be treated as 2d ortho for most things.

so I take pos and subtract that from the current transform., atan for the angle and that gets rotation.
Let me try it robert.
By the way man, thanks. You’re becoming a regular guru type dude.