- Home /
rigid body Clone Instance not behaving like original
Hi. I have a sphere that is being launched from a catapult. I parented the sphere to the catapult so that the dynamics act locally, because the catapult moves fairly quickly and the simulation was flipping out on launch. Parented, the simulation looks nice and realistic, but the problem arises when the catapult moves at all - since it's local, even in mid air the object moves and rotates with the catapult. So, to solve this issue, I instantiated an object upon launch in world space and copy the position, rotation, and velocities with the following code:
cloneObj.rigidbody.useGravity = true; cloneObj.rigidbody.velocity = origObj.rigidbody.velocity; cloneObj.rigidbody.angularVelocity = origObj.rigidbody.angularVelocity; cloneObj.rigidbody.rotation = origObj.rigidbody.rotation;
var currentPos = origObj.position; var currentRot = origObj.rotation;
origObj.position = Vector3(500,0,0); origObj.rigidbody.useGravity = false;
cloneObj.position = currentPos; cloneObj.rotation = currentRot;
The thing is, the simulation on the cloned object reacts differently. When it collides with an object, it seems like it doesn't get the angular velocities the same way and almost has no torque when it bounces off something, and doesn't reverse direction when it hits another object, like the original does. Is there something else I'm not transferring correctly from the original to have the clone behave physically like the original?
Answer by dbokser · Mar 17, 2010 at 03:25 AM
It seems like I solved it by setting the cloneObj mass to 1. Why would this be? The mass is set to 1 in the prefab anyway, so why would not explicitly setting it change the results of the simulation?
cloneObj.rigidbody.useGravity = true;
cloneObj.rigidbody.velocity = origObj.rigidbody.velocity;
cloneObj.rigidbody.angularVelocity = origObj.rigidbody.angularVelocity;
cloneObj.rigidbody.rotation = origObj.rigidbody.rotation;
cloneObj.rigidbody.mass = 1;