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 Tekksin · Oct 28, 2013 at 10:24 AM · animationcolliderchangebox

What's wrong with my Script? Changing Collision

I want the collision to change when the character ducks/squats and it DOES. But I also want the collision to change when the character jumps. I currently tried this, but it doesn't work for some reason. Does anybody know why? Thanks.

 function Update () {
     
     var colliderBox = gameObject.GetComponent(BoxCollider); //controlls collider box size
     var AT = gameObject.GetComponent(AnimateTexture); //Store AnimateTexture Script
     
     if(Input.GetKey("space")){
         AT.rowNumber = 3; //Player jumping animation
         colliderBox.center = Vector3(0.03, -0.01, 0);
         colliderBox.size = Vector3(10, 6, 1);
     }else{
         colliderBox.center = Vector3(0.03, -0.29, 0);
         colliderBox.size = Vector3(0.44, 0.37, 1);
     }
 
 
 
     if(Input.GetKey("s")){
         AT.rowNumber = 4; //Player squats down
         colliderBox.center = Vector3(0.03, -0.38, 0);
         colliderBox.size = Vector3(0.44, 0.16, 1);
     }else{
         colliderBox.center = Vector3(0.03, -0.29, 0);
         colliderBox.size = Vector3(0.44, 0.37, 1);
         }
 }
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

1 Reply

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

Answer by EvilWarren · Oct 28, 2013 at 11:44 AM

Your collider values look strange but I'm just going to assume you know what you're doing with them. The problem is your second if statement wipes out any values you assigned in the first statement, as one of the tow conditions in the second will always be executed.

Try this

 function Update () {
     var colliderBox = gameObject.GetComponent(BoxCollider); //controlls collider box size
     var AT = gameObject.GetComponent(AnimateTexture); //Store AnimateTexture Script
  
     if(Input.GetKey("space")){
        AT.rowNumber = 3; //Player jumping animation
        colliderBox.center = Vector3(0.03, -0.01, 0);
        colliderBox.size = Vector3(10, 6, 1);
     }else if(Input.GetKey("s")){
        AT.rowNumber = 4; //Player squats down
        colliderBox.center = Vector3(0.03, -0.38, 0);
        colliderBox.size = Vector3(0.44, 0.16, 1);
     }else{
        colliderBox.center = Vector3(0.03, -0.29, 0);
        colliderBox.size = Vector3(0.44, 0.37, 1);
     }
 }
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 Tekksin · Oct 28, 2013 at 01:18 PM 0
Share

if, else if, else. I gotta remember that pattern.

And yes, my values are ridiculous because I was trying to see in the game preview window the difference in size of the boxcollider. So I gave some astronomical number lol. Forgot to change it to something more realistic before posting. But all that aside, THAN$$anonymous$$ YOU!!!! I believe I tried something similar, but because of my insane number values, the collision grew large enough to hit my enemy and the player was dying immediately, and I didn't know why haha. So I'd also like to thank you for mentioning my ridiculous collision values, too. I probably would've overlooked it otherwise, and continued wondering what was going on lol. Thanks! I'd thumb your comment, but I don't have the rep for that yet.

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

16 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

Related Questions

Box Collider not moving with animation 1 Answer

Internal collisions 1 Answer

How to move BoxCollider with animation? 1 Answer

Player Animation change when pickup Weapon 0 Answers

what is the best way to detect if an object has been clicked on? 1 Answer


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