I don’t quite get your objects setup, maybe you can post your code…
wild guesses:
-did you enable any freezePosition in Editor?
-is the Rigidbody set to kinematic?
-mass is within reasonable range all the time? Unity - Scripting API: Rigidbody.mass
I am still not sure what exactly you are trying to achieve, i gave it a try, i have no editor at hand, so i did this without syntax check:
//toggles masses of the Object, object names S1 will have low high at start
private bool thisHasLowMass = false; //we just use one bool to toggle mass
private Transform thisTransform;
private Rigidbody thisRigidbody;
private float massLight = 1.25F;
private float massHeavy = 1.35F;
private float aDragLight = 0.1F;
private float aDragHeavy = 0.5F;
private float dragLight = 0.2F;
private float dragHeavy = 0.4F;
void Start(){
//we save the reference to these Components, so the engine doesn't have to check if it is present on each call
thisTransform = transform;
thisRigidbody = rigidbody;
//String compares are generally considered "slow",
//so we only do it at once Start() and only for one of the 2 objects
if(thisTransform.name=="S1"){
thisHasLowMass = true;
}
thisRigidbody.useGravity=true;
//initially do one Swap to set the values, therefore S1 will have high mass on start
SwapMasses();
}
void OnMouseDown(){
//not sure if you want this, check http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnMouseDown.html
}
void Update(){ //Consider Fixed Update if you want to add Forces later
//this should be able to recognize your left mouse click
if(Input.GetKeyDown("mouse 0")){ //GetKeyDown is only true for one Update() frame
SwapMasses();
}
}
//if you want to apply forces (thisRigidbody.AddForce(.. ), do this here
void FixedUpdate(){
}
private void SwapMasses(){
if(thisHasLowMass){
thisRigidbody.mass = massHeavy;
thisRigidbody.angularDrag = aDragHeavy;
thisRigidbody.drag = dragHeavy;
}else{
thisRigidbody.mass = massLight;
thisRigidbody.angularDrag = aDragLight;
thisRigidbody.drag = dragLight;
}
thisHasLowMass = !thisHasLowMass; //toggles this bool
}
balancing the seesaw (thats the correct name for your construction if i interpreted it right) through exchanging 2 weights through mouseclick is a though challenge.
Maybe if you state your goal it would be more obvious what you try to achieve with this arrangement.
if you want to stabilize your seesaw artificially you could use a PID-Contoller that takes:
-the angle difference to 180 as error
-the weight difference between the 2 objects as output
so the weight of the objects would change based on the angle of the seesaw, just tune the parameters right and you will be stable in a few Physic-Frames
you are right i am still confuse total mass of object so, when i drag any other object at of the end it should get balance on the weight of drag object
-So you are trying to create a game where you have to balance out a seesaw?
-You drag objects on it with your mouse?
-and the goal is to balance it out?
script your own thing where you check which weights are left and right and balance it out manually if the weight difference is within a certain margin and balance it out using a PID-Controller and Rigidbody.AddTorque
or try this contraption, it allows a small weight-difference and will still even out at 180°:
hey, marrt, i have solve that problem now if i drag different object example(200gm, 500gm ) on certain point how should manage the mass so it can be stable at different position