- Home /
(Unity2D) having a gameobject "orbit" around another object.
I'm currently learning 2D unity as part of a college game design course. For my project I decided to make what essentially boils down to a Zelda clone since in the process of making it I would be able to learn many of the essentials (Such as AI, Static variable management, saving and loading, etc).
One of the issues I'm having is with one of the enemy types. If any of you ever played the 2D GameBoy Color Zelda games, there is a knight enemy with a ball and chain that sort of "orbits" around him at a fixed radius.
For the life of me I can't seem to reproduce it in code. I've searched around the forums and found fixed orbit code for 3D projects, but so far none for 2D. I tried setting it's pivot point far outside the center of the sprite and altering it's transform.eulerAngles.z, but that just caused it to rotate in place, rather than around it's actual pivot point.
I don't have any code to show since I don't know where to start, but I do have a diagram of the desired effect.
Please ignore the fact that the circle in the diagram below is in fact an oval. It's supposed to be a circle but I'm in kind of a rush.
Thanks.
Answer by screenname_taken · Dec 09, 2014 at 01:23 PM
If nothing else works, you can make the ball a child of an empty gameobject that is at the exact place you want the pivot to be, and rotate that.
Rotate the empty object by it's Eulerangles, or via transform.rotate?
I'd do it via rotate or an animation cause i'm lazy.
I'm not sure if 2d objects have transforms but if so you could use transform.RotateAround on the ball gameObject and set the point to the Enemy transform.position
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Switching Cameras at runtime 1 Answer
Is it possible to import from unity into blender 1 Answer
Increase Jump Through Mouse Clicks? 1 Answer
A node in a childnode? 1 Answer