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 Medi731 · Mar 08, 2013 at 12:11 PM · rigidbodyrigidbody-collisionexpansion

Making a Gameobject expand!

Hello,

I've recently started to use Unity so I am quite fresh to the experience, please bear with me.

At the moment I'm currently able to make a prefab sphere instantiate on multiple targets within my game, however I'm looking to make these spheres expand and contract. Basically, when the player spawns a sphere I want it to start to expand until it either hits the wall of the box or another sphere. When it does so, I want a random sound (out of 25) to be played on collision and for the sphere to contract. At this moment I have near to no idea of how to structure this expansion, whether I use transform.localscale, rigidbodys or animation, I am pretty stuck.

So any help and tips would be much appreciated, sorry and thanks!

Here is an image of what the project looks like so far. alt text

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

Answer by Statement · Mar 08, 2013 at 01:52 PM

You could perform a simple sphere collision test for the spheres and use a radius test for the walls for the ones that are out there on the outer faces.

Sphere collision is a simple as taking the distance between two spheres and check if it is less or equal to the sum of the two spheres radius. If it is, then the sphere has collided with another sphere. To check if a sphere is large enough to hit the wall, you could just check if the radius is greater than or equal to the distance to the wall.

Once you have detected these conditions, play your random sound. You might also want to adjust the spheres radius you are changing so it doesn't visually overlap.

If you imagine we hit a condition for where you are increasing the radius of sphere1, consider this:

 // since a collision happens when
 // distance <= sphere1.radius + sphere2.radius
 sphere1.radius = distance - sphere2.radius;

And likewise you could do the same for hitting a wall

 sphere1.radius = distanceToWalls;
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

11 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

Related Questions

moving an object from point to point using force 1 Answer

How may I observe expected physical interactions while using Rigidbody.MoveRotation()? 1 Answer

How to make an object only respond to a character? 2 Answers

Rigidbody Precise Colliders 1 Answer

I want to get a projectile to return the surface tag but it returns untagged. 3 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