- Home /
How to rotate an object around another facing to mouse?
Im making a 2D game and i need to make a pointer that rotates around a plane and points to mouse. How can i do it? Thanks. Look at geometry wars :http://www.youtube.com/watch?v=u83rxKmzu6E , ship has triange that rotates around ship and points to mouse. How can i do this?
public Transform ship;
void Update()
{
transform.RotateAround(ship,30);
}
Could you at least explain in more detail what you want?
As @cdrandin indicated, a much better description is needed. A drawing or a screen shot would also be very helpful. There are multiple different ways to interpret your question.
Indeed there are a variety of possible interpretations to your question. I.e. you write about planes but I wonder if they are those of the mathematical or the flying variety!
If it's the latter, are you perhaps asking how to create a target-like pointer that sticks to the (air)plane, to highlight it, and has a second element that somehow visually connects this target to the mouse pointer?
Added screen, that triangle rotating around ship and points to mouse.
Answer by robertbu · Jul 22, 2013 at 02:16 PM
There are a number of posts with different solutions on getting a 2D object to follow the mouse. Here is one:
http://answers.unity3d.com/questions/411419/rotationy-flips-when-turning-around-x-axis.html
You can handle the rotate around part in a couple of ways. First, you could make your texture large enough to overlay the underlying ship like this:
Where the blue is the boundary of the image. Everything but the arrow is transparent. So when this image is centered on the ship, the arrow would be at the boundary of the ship.
The second solution would be place an empty game object at the center of the ship. The arrow would be a child at the correct position. The rotation code goes on the empty game object.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Flip over an object (smooth transition) 3 Answers
Rotating object with a mouse movement 0 Answers
How to rotate Character on Y axis along with the mouse rotation? 0 Answers
Distribute terrain in zones 3 Answers