• 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 Karl-Einarb · Apr 04, 2012 at 06:46 PM · height

Problem finding the real in-game height of an object

Hello all,

I have problems finding the real height of my character in game.

This is some of what i have tried:

 PlayerHeight = this.GetComponent<CharacterController>().height;
 PlayerHeight = this.transform.collider.bounds.size.y;
 PlayerHeight = transform.FindChild("ChildName").transform.localScale.y;
 PlayerHeight = transform.FindChild("ChildName").GetComponent<MeshFilter>().sharedMesh.bounds.size.y;
 PlayerHeight = this.transform.lossyScale.y;
 PlayerHeight = this.transform.localScale.y;

I have tried out more possibilities, but havent kept track of the all.

I Have also tried to find values in the inspector related to the in-game height but I can only find Scale values.

But heres the thing, i have implemented a system to see how far the player is from the ground(Altitude) and that is 0 when I stand on the ground and the value increments when the player is ascending.

So since I'm able to calculate the height of the player from the world, shouldent it be possible to calculate the real height of the player from bottom to top?

I hope someone here is able to help me out :) and sorry for all the spaces, the text editor have bugged.

EDIT:

I might add why i need the real in game height.. I'm gonna use it to calculate fall damage and animations based on the size of the character insted of static values. Example: if (FallDistance > (CharacterHeight * 10) = Death.

Regards

Karl-Einarb

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by kromenak · Apr 04, 2012 at 06:58 PM

Is the first one not giving you accurate values? The height value of a character controller should give you the height of the player in world units (default is 2). Based on the way the physics system works, one unit in world space should equate to one meter in the real world, so that things interact correctly and fall at the correct speeds.

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 Karl-Einarb · Apr 04, 2012 at 07:31 PM

Thank you! :)

But then i have another question.. I tried to reset the GUI to show info from PlayerHeight = this.GetComponent().height; again. And it showed the value 2, which should be correct.

Then i tried to Scale my Character upwards (It also scaled the Character Controller), and i tried to re run the game, and the value is still 2.

Is there any way to let this value scale with the actual size of the character? ,Thank you! :)

But then i have another question.. I tried to reset the GUI to show info from PlayerHeight = this.GetComponent().height; again. And it showed the value 2, which should be correct.

Then i tried to Scale my Character upwards (It also scales the Character Controller), and i tried to re run the game, and the value is still 2.

Is there any way to let this value scale with the actual size of the character?

Comment
Add comment · Show 1 · 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 kromenak · Apr 04, 2012 at 07:36 PM 0
Share

Yeah, there are several instances throughout Unity where those sorts of values do not take scale into account - but then again, it probably makes sense that they don't.

What you can do is multiply the height by the character's scale:

 GetComponent<CharacterController>().height * transform.lossyScale.y

"lossyScale" gives you the scale of the object, including all parent objects, while "localScale" gives you just the local scale of the object.

Just as an aside, I would suggest not modifying the scale of your CharacterController if at all possible to avoid unneeded complications later on. You'll probably be finding issues and be like "ah, forgot to take scale into account"

avatar image
0

Answer by Karl-Einarb · Apr 04, 2012 at 10:15 PM

Okey, Thank you guys for clearing this up! Appreaciate it :)

Comment
Add comment · Show 1 · 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 HolBol · Apr 04, 2012 at 10:16 PM 0
Share

This isn't an answer to the question. Use the Comments section, it's not as if it isn't there.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Find Game Objects Height Orthographic View 1 Answer

Kinect issue with Character Movement while in flight 0 Answers

Guided missile's height 2 Answers

Can you get the height that you are holding the phone? 2 Answers

How to change the Width and Height in the script C#? (New Gui Unity 4.6 beta) 2 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