• 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 Tekksin · Oct 30, 2013 at 06:16 PM · collisionplatformeroncollisionenter

tranform parent makes character blow up in size

So I have a rigidbody character that is supposed to ride platforms for some sections. I have a code that works, but it also affects how large the character is. Because the character is scaled by 2 on the xy axis, and the platform is scaled by 5 on the x axis.

Is there a way to keep the character on the moving platform, WITHOUT transforming the size?

 function OnCollisionEnter(theCollision : Collision){
     if(theCollision.gameObject.tag == "Mover"){
         transform.parent = theCollision.transform;
     }
 }
 
 
 function OnCollisionExit(theCollision : Collision){
     if(theCollision.gameObject.tag == "Mover"){
         transform.parent = null;
     }
 }![alt text][1]


[1]: /storage/temp/17247-2.png

1.png (6.9 kB)
2.png (3.2 kB)
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 Josh707 · Oct 30, 2013 at 06:27 PM 0
Share

Well it's generally a good idea to keep most if not all root objects at 1,1,1 scale, but since you haven't, you will either have to make the current bridge object a child of an empty with 1,1,1 scale or manually calculate the scaling to apply to your player. Or figure out another way to move the player without parenting him to the platform.

avatar image Tekksin · Oct 30, 2013 at 06:36 PM 0
Share

I had to enlarge my player box, or else it would have been tiny, as seen below. Is there a different way of scaling an object? Because it just doesn't fit in the world, unless the size is doubled.

alt text

3.png (3.6 kB)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Owen-Reynolds · Oct 30, 2013 at 07:00 PM

Are you using code to occasionally rescale the player (not just in start?) The problem is when you're childed, your scale isn't really your scale.

Suppose your guy is scaled (2,2,1). If you put him in a size (4,4,1) parent, the player won't change size, but the scale will snap to (0.5, 0.5, 1). That's the scale in the parent. If you take those #'s, times the parent #'s you get back (2,2,1). Unlike position/localPosition, there's no easy way to read or set a child's actual scale (which is what Josh07 writes.)

The problem is, if you set your childed player localeScale (the only scale there is) to (2,2,1), the real scale is suddenly (2*4, 2*4, 1*1).

Terrible hack, but if you have to rescale the childed player, could unchild it first: Transform par=player.parent; player.localScale=...; player.parent=par;. The other way is to divide by the parent scale whenever you are childed (localScale.x = whatIwant/parent.localScale.x;)

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 Tekksin · Oct 30, 2013 at 07:24 PM 0
Share

Oh that makes sense... and there's no way to have a parented object adopt the translation, and not the scale?

The script example you showed me makes no sense. Where do I put that code? Can you show me an example in the code I have above? I have no idea what childing is. sigh...

avatar image Tekksin · Oct 30, 2013 at 07:31 PM 0
Share

if I set the player back to 1x1x1, is there a script I can write that changes the size to 2x2x2 so that it fits in the world better?

avatar image Owen-Reynolds · Oct 30, 2013 at 09:17 PM 0
Share

In the Computer Science world, giving something a parent is called "childing" that thing, since you are making it into a child. For example, you "child" the player to the platform (by making the platform the player's parent.) Parenting is making something the parent -- you might parent the player to a gun.

Some Unity people say it the other way, that giving something a parent is "parenting" it.

avatar image
0

Answer by Tekksin · Oct 30, 2013 at 08:14 PM

I fixed the problem with some 2d trickery. duplicated the platform that was scaled to (5, 1, 1) and changed the new one to (1, 1, 1). Then I just moved the (5, 1, 1) version forward, and increased the box collision on the (1, 1, 1) box to (5, 1, 1). Now you can't tell the difference. Damn, I wonder if that scaling issue with parenting is going to rear its ugly face any time soon...

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Collision with no contact? 2 Answers

Unparent object on collision? 3 Answers

Transform collider not detecting collision on rigidbody collider 2 Answers

onCollisionEnter function called from another object. 1 Answer

Change Direction on Collision 6 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