- Home /
Rotate around, but track the mouse
This is a 2d side scroll setup. I'm trying to have an object (lets just say its a gun or something) rotate around the player but still track the mouses movement. I honestly don't know where to start for this one as rotation stuff just doesn't click well for me. Anyone have an idea to solve this?
Answer by 3dDude · Jul 13, 2010 at 12:50 AM
this should work..... attach this script to the gun :)
function Update () {
var position = Input.mousePosition; newposition = Vector3(position.x,position.y,-camera.main.transform.position.z); var lastposition = camera.main.ScreenToWorldPoint(newposition); transform.LookAt(lastposition); }
Your answer
Follow this Question
Related Questions
How to rotate an object around a fixed point so it follows the mouse cursor? 1 Answer
How to make an object rotate on the y axis towards the mouse? 3 Answers
Rotate object following mouse movement. Object jumps/ flips 1 Answer
Rotation of the mouse activates a boxcollider2d in javascript. 1 Answer
i want to rotate an object when i move my mouse over an UI image 1 Answer