# making elastic object

 0 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 more ▼ asked Jun 16 '12 at 03:40 PM smtabatabaie 60 ● 14 ● 14 ● 17 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

2 answers: sort voted first
 0 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) more ▼ answered Jun 16 '12 at 04:15 PM aldonaletto 41.4k ● 16 ● 42 ● 197 fantastic simple suggestion. Jun 16 '12 at 08:29 PM Fattie 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 Jun 17 '12 at 06:19 AM smtabatabaie 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. Jun 17 '12 at 05:43 PM aldonaletto add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 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 more ▼ answered Jun 16 '12 at 04:10 PM ExTheSea 2k ● 12 ● 23 ● 30 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Topics:

x1870
x9
x5

asked: Jun 16 '12 at 03:40 PM

Seen: 885 times

Last Updated: Jun 23 '12 at 03:12 PM