Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by nhftk12 · May 21, 2011 at 11:14 AM · collidertransformsizecenter

how to change sphere/capsule collider, it sizes and the center

I made an enemy that can transform into ball and robot. The enemy start as a ball with sphere collider and when I get closer it transform into robot. The problem is when it transform into robot, it's need to change the collider onto capsule collider because it's legs don't have a collision so they go through the floor. I sucsseed to switch between the colliders tipes but when I tried to change the size and centers - it don't do that and don't change the collider tipe anymore. How do I change the collider tipe, size and centers?

This is what I did so far:

 function Attack ()
  {
      if (canAttack)
      {
          rigidbody.AddForce(transform.up * 40);
          animation.Play("TransformRobot");
          yield WaitForSeconds (0.3);
          Destroy(collider);
          var capsuleCollider = GetComponent ("CapsuleCollider") as CapsuleCollider;
          capsuleCollider.height = 5;
          capsuleCollider.radius = 2;
          capsuleCollider.center.y = -0.5;
          canAttack = false;
      }
  }
  
  function FindWaypoints ()
  {
      if (!canAttack)
      {
          rigidbody.AddForce(transform.up * 40);
          animation.Play("TransformBall");
          yield WaitForSeconds (0.3);
          Destroy(collider);
          var sphereCollider = GetComponent ("SphereCollider") as SphereCollider;
          sphereCollider.radius = 2;
          canAttack = true;
          rigidbody.AddForce(transform.forward * 100);
      }
  }
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 TheDemiurge · May 22, 2011 at 08:38 AM 1
Share

Does your GameObject actually have both a CapsuleCollider component, and a SphereColliderComponent? You can have both and enable/disable one on-demand, so you don't have to keep changing dimensions on them.

avatar image nhftk12 · May 22, 2011 at 12:16 PM 0
Share

Now I have (after you asked). But how I can enable/diable them when I need?

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by cityseeker · May 19, 2012 at 01:34 AM

Now I have (after you asked). But how I can enable/diable them when I need?

ANSWER: What i did was i created two empty game objects underneath my Player GameObject. I named one CapsuleCollider and another BoxCollider. I attached a Capsule Collider to the one named Capsule Collider and I attached a Box Collider to the one named BoxCollider. I have a GameMaster Script attached to another empty GameObject where I have created two public GameObject capsuleCollider and public GameObject boxCollider. From the inspector i drag the appropriate BoxCollider GameObject to the GameMaster public GameObject boxCollider field. Then I can just disable them in the script with

capsuleCollider = GameObject.GetComponent(<CapsuleCollider>);

 capsuleCollider.enabled = false;
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 allghoichorchoj · May 10, 2017 at 06:59 PM 0
Share

and if i wanna use other capsule?

avatar image
0

Answer by subcod · Aug 13, 2012 at 01:15 AM

Genius cityseeker! That even solved my 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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

OnCollisionEnter, collider is the gameobject 1 Answer

Changing the size of a text object to only be as long as the letters 0 Answers

Scale script don´t work 0 Answers

Move sprite depending on its collider position 1 Answer

How to Move Player in Particular Direction Without holding Down a Button? 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