Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 BDP1 · Apr 02, 2013 at 08:30 AM · colliderrotatesphere

Problem rotating spheres around empty parent

I am working on a 2d sidescrolling game.

I am trying to implement a "shield" for the player's ship made up of 4 spheres. These 4 spheres are set as children of an empty parent object I have attached to my ship. My goal is to have them spin around the player ship's Z axis.

I figured I could create the empty parent and set it on my ship's center, add the 4 spheres to the empty object as children, zero out their locations and then move them in their respective directions to achieve a north south east west orientation of 4 spheres spaced 3 units away from the center. I then created a script and attached it to the empty parent object which would rotate the parent 10 degrees a second.

Here is my script, very simple but maybe I'm using rotate wrong. I will explain below.

 #pragma strict
 var myShieldTransform : Transform;
 
 function Start () {
     myShieldTransform = gameObject.transform;
 }
 
 function Update () {
     //Rotate the object around its Z axis at 10 degree/second.
     myShieldTransform.Rotate(0, 0, (10 * Time.deltaTime));
 
 }

The script will rotate all 4 spheres as I expected, however, they become skewed compared to their original orientation while moving around. I'm kind of stumped as to why. I have tried making sure my ship, empty parent, and all spheres are at 0 in the Z axis. The sphere size and scale does not change while running, but the collider's green wireframe does not stay consistent with the sphere's borders. I have attached an image to clarify.

Image on IMGur

Thank you for any help. I don't want to proceed until I figure this out. When I fully implement this the shield not having matching colliders will look funny when deflecting enemy fire.

Comment
Add comment · Show 3
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 cdrandin · Apr 02, 2013 at 08:44 AM 0
Share

You said it is a 2D game, if they are being skewed try to forcefully align it in the axis you are not using to keep it as much aligned as possible, if the problem persist then come back.

avatar image BDP1 · Apr 02, 2013 at 10:06 PM 0
Share

Hello Robert.

Thank you for your input. I have "unparented" my shield. When it is not attached to my player's ship the colliders stay consistent throughout the rotation. You're the man! When I use this code no problems arise.

 #pragma strict
 var myShieldTransform : Transform;
 var shieldPivotPoint : GameObject;
 
 function Start () {
     myShieldTransform = gameObject.transform;
     shieldPivotPoint = GameObject.FindGameObjectWithTag("shieldpivot");
 }
 
 function Update () {
     myShieldTransform.transform.position = shieldPivotPoint.transform.position;
     
     // Slowly rotate the object around its Z axis at 10 degree/second.
     myShieldTransform.Rotate(0, 0, (10 * Time.deltaTime));
 
 }

Thank you for your help but I am still curious as to why this happens. I can send you any script you would like or perhaps the project. I am a student developing for my portfolio so I see no reason to be secretive of my code.

Is there anyway to give you credit for answering this in a comment?

avatar image robertbu · Apr 02, 2013 at 10:21 PM 0
Share

I converted my comment to an answer. If you click the checkmark on the left of the answer, it will close the question out and give me a bit of $$anonymous$$aram.

Now that you know it is the parent/child relationship between the two that is causing the problem, go back and look at any rotation or scaling that is going between the root object (ship) and pivot point. This includes both local and global rotations in any of the object that would have been higher up the parent/child chain. I suspected when I posted my original suggestion that somewhere in that chain something is rotating, though given this is a 2D game, I couldn't see why would want to. You can also run the game and look at the rotations in the Inspector of all the objects.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Apr 02, 2013 at 04:13 PM

I like figuring out rotation problems, but from the information given, I cannot figure out how you are getting this behavior. Here is something to explore. Make the four spheres a child of the empty game object as you've done here, but don't make it a child of the ship. Next an empty game object as a child of the ship at the pivot point. Now in the script above, have it track the pivot object. That is, your shield will follow the ship but it will not be a child of the ship. This may or may not fix the problem, but it will tell you something about the nature of the problem.

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

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

10 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

Related Questions

How do I rotate a Collider? 3 Answers

Rigidbodies not reacting to one another 2 Answers

Make a capsule collider BETWEEN 2 objects 0 Answers

What is the simplest way to get a sphere to rotate as it moves in game? 1 Answer

Quick Shortcuts for Rotation 0 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