|
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?
(comments are locked)
|
|
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) 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
(comments are locked)
|
|
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
(comments are locked)
|
