Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Codelyy · Jan 26, 2016 at 12:20 AM · 2drotationmovementobject

2D rotation around a object

What I'm wanting is to have a object rotate around another object in a circle in 2D basically having the object rotate at a certain speed though I'm not sure on how to do something like this.

Most of the stuff I found was how to rotate a object around itself when what i want is a object to rotate around another object/

Any help?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by milleniu · Jan 26, 2016 at 12:24 PM

Hi, perhaps there's another way I don't know, but I'm curently using this in my project :

 using UnityEngine;
 using System.Collections;
 
 public class DoRotateAround : MonoBehaviour {
 
     public float speed;
     public Transform target;
     
     private Vector3 zAxis = new Vector3(0, 0, 1);
 
     void FixedUpdate () {
         transform.RotateAround(target.position, zAxis, speed); 
     }
 }
 

It's using the rotateAround function, and since you're in 2D, you only need to use zAxis for the rotation.

You can choose the center of the rotation with target and speed with. Passing from clockwise to counter clockwise rotation just require a negative speed.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Codelyy · Jan 28, 2016 at 01:41 AM 0
Share

I tried using that function but ins$$anonymous$$d of rotating around the object, they rotate around themselves.

avatar image milleniu Codelyy · Jan 29, 2016 at 12:08 AM 0
Share

How did you use the script ?

For example if you want _objectA to rotate around _objectB, you need to put the above script on _objectA, and set target to _objectB in the inspector.

avatar image falconstrike209 · Jan 20, 2021 at 09:23 PM 0
Share

@milleniu hey! I know this is old, But I was wondering if you know a way to do this, but instead of the object rotating around with a fixed speed, is there a way to make it rotate towards the mouse?

avatar image
0

Answer by SterlingSoftworks · Jan 26, 2016 at 06:27 AM

Rotating Sprites

Is this what you're trying to go for? (sorry that it's a .zip.. Wouldn't accept my .gif of this for some reason)

If so, add a rigid body to both objects you're wanting to have this happen with. On the stationary ( or the one you want the other object rotating around) add a "Hinge Joint 2D" and drag the object that will be rotating into the "Connected Rigid Body" slot. If you want it to continuously rotate, enable the "Motor" and set it to the speed you want. Otherwise when it's hit (when it has a collider) it will rotate freely based on it's mass.

Haveeeeee fun :D (if this is what you were wanting)


2016-01-25-2216-56.zip (33.2 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by sIothman · May 28, 2016 at 03:51 PM

We'll try to use what milleniu suggested. After all, knowledge is never enough. But, I achieved to build a trap rotating with a Hinge Joint 2D component and changing the properties.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by triangle4studios · Jan 20, 2021 at 10:30 PM

Rotation in 2D is almost the same as Rotation in 3D.
I have quickly thrown together a script and this 2 minute video to help you get started.


You can also refer to the Unity RotateAround API which is basically what this script below is doing, but the video explains how to do it in 2D.


 using UnityEngine;
 
 public class Orbit2D : MonoBehaviour
 {
     public GameObject target;
     public float speed = 10;
     public Vector3 direction = Vector3.up;
 
     void Update()
     {
         transform.RotateAround(target.transform.position, direction, speed * Time.deltaTime);
     }
 }


Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image falconstrike209 · Jan 20, 2021 at 10:34 PM 0
Share

oh, uh, this page is really old lol. I just needed help with something similar to this, so I put a comment in the top question (you can read it if you want)

avatar image triangle4studios falconstrike209 · Jan 21, 2021 at 02:39 AM 0
Share

Are you meaning, if you move the mouse, the object then rotates around the target object?

avatar image falconstrike209 triangle4studios · Jan 21, 2021 at 11:51 PM 0
Share

yes, but it rotates around the other object at a set distance from it, and points towards the area closest to the mouse. (I'm using the object to indicate the direction the player will dash, which is towards the mouse, so the object i'm talking about rotating will be rotating around the player, and needs to point to the mouse)

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

66 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2d Movement Messes up when cube is rotatated 0 Answers

Basic 2D movement C# - Key presses cancel eachother out 4 Answers

Rotating an object towards target on a single axis 2 Answers

How should I move a sprite in a direction based on the rotation of a child? 1 Answer

making an object move to a certain point 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges