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 Backward pieS · Mar 14, 2013 at 11:20 PM · vector3collidersscale

Vector3.Scale and rotated colliders

I'm building a puzzle game, and I would like to horizontally flip pieces randomly when instantiated via code. Each piece has multiple box colliders and mesh objects as children to a container object.

I've tried using Vector3.Scale on my container object to flip everything at once by scaling in X by -1. Things looks great at first glance, but any of my collider objects that are rotated do not come through correctly.

The (rotated) meshes for the collider objects (just there to help me visibly see what's going on) flip properly, but their colliders no longer match their size and orientation with the mesh. They keep their original orientation and scale down somewhat(?).

Here's the code I am using:

 Vector3 flipVector = new Vector3(-1, 1, 1);
 transform.localScale = Vector3.Scale (transform.localScale, flipVector);

Does anyone know a good way around this? I can manually rotate/scale the individual elements if I have to, but that seems like a lot of extra work...

Comment
Add comment · Show 2
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 robertbu · Mar 14, 2013 at 11:24 PM 0
Share

Why not just rotate the container object? There are lots of ways. Here's one

 transform.eulerAngles = new Vector3(180,0,0);

or since you are using localScale, maybe you need:

 transform.localEulerAngles = new Vector3(180,0,0);

This flips it over on the x axis.

avatar image Backward pieS · Mar 14, 2013 at 11:56 PM 0
Share

Simply rotating the container creates other problems for me, because the z-values of the elements within it need to be maintained with respect to the world (hard to explain). So I'd still have to do a lot of manual fixes.

1 Reply

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

Answer by Backward pieS · Mar 15, 2013 at 12:49 AM

Okay, that wasn't so bad.

What I did was handle the individual components separately. Those that no offset or rotation could simply be scaled by -1 in X to be flipped.

The rotated elements needed got a local 180 spin, then I used Reflect on their localPosition. Offset colliders that weren't rotated got the same Reflect treatment but without the spin.

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

Issues scaling a object with children colliders 1 Answer

Scaling objects over time? 3 Answers

physics.OverlapSphere colliders 1 Answer

Scale objects of different rotations by a single direction 1 Answer

Maintaining length to width ratio while scaling GUI's (GUI.matrix )? help 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