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
3
Question by smtabatabaie · Jun 16, 2012 at 03:40 PM · physicsjoinelastic

making elastic object

hi , I have two spheres which there's a long cube between them and each side of this cube is connected to one of these spheres. these spheres are movable . I wanted the cube between them to be elastic and be connected to these spheres and changes it's scale and stretches when the spheres widen . is there a physic material or a joint which can do that?
thanks

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

2 Replies

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

Answer by aldonaletto · Jun 16, 2012 at 04:15 PM

Joints are intended to create some specific physics behaviours - they don't modify the object mesh. You can achieve the effect you want with a simple script (attached to the cube):

 var ballA: Transform; // drag sphereA here
 var ballB: Transform; // drag sphereB here
 var scale0: Vector3; // initial localScale
 
 function Start(){
   scale0 = transform.localScale;
 }
 
 function Update(){
   var pA = ballA.position;
   var pB = ballB.position;
   transform.position = (pA+pB)/2; // place the cube in the middle of A-B
   transform.LookAt(pB); // make it look to ballB position
   // adjust cube length so it will have its ends at the sphere centers
   var scale = scale0;
   scale.z = scale0.z * Vector3.Distance(pA, pB);
  // stretch it in the direction it's looking
   transform.localScale = scale;
 }


This works fine for a simple Unity cube, because its localScale is numerically equal to its dimensions, but may produce bizarre results for imported objects. A more general, sophisticated and complicated solution would be to use bones (take a look at Mesh) in the docs)

Comment
Add comment · Show 6 · 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 Fattie · Jun 16, 2012 at 08:29 PM 0
Share

fantastic simple suggestion.

avatar image smtabatabaie · Jun 17, 2012 at 06:19 AM 0
Share

thanks os much ,I think this is what I should do , but the other problem is how can I make the edges of the cube fully connected to the spheres . cause if the rotation of the cube changes , the edges will not be fully connected to the spheres and it will look a little bit unrealistic

avatar image aldonaletto · Jun 17, 2012 at 05:43 PM 0
Share

If the cube has X and Y scales set to 70% or less than the sphere diameter (scale = (0.7,0.7,1.0), for instance) its corners will be hidden inside the spheres, and you will see a cubic bone linking them. If the X and Y scales are bigger than 0.707, the corners will appear no matter what you try.

avatar image Ideadam · Jun 21, 2014 at 12:57 PM 0
Share

Can you please suggest how to achieve this using bones? I am trying to create a 2d slingshot effect.

avatar image meat5000 ♦ · Jun 21, 2014 at 12:59 PM 0
Share

Separating bones manually will usually cause a mesh to stretch. I suppose this can help you achieve what you want.

Your question was rejected as it was a general design question, not a Unity specific one.

Show more comments
avatar image
1

Answer by ExTheSea · Jun 16, 2012 at 04:10 PM

You have to make a physics material and try a friction around 1.

Got it from here:

http://answers.unity3d.com/questions/58794/getting-realistic-bounces-using-physics-materials.html

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

How to bend slingshot on stretch? Like angry birds 2 game 0 Answers

Please help! interactive physics 0 Answers

How to make objects non-penetrable, inelastic 0 Answers

How to stop objects from losing energy due to joints? 0 Answers

2D 360 degress platformer example needed 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