x


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?

more ▼

asked Mar 17 '10 at 03:11 AM

dbokser gravatar image

dbokser
11 1 1 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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;
more ▼

answered Mar 17 '10 at 03:25 AM

dbokser gravatar image

dbokser
11 1 1 3

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

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

By RSS:

Answers

Answers and Comments

Topics:

x2488
x1868
x1787
x16
x15

asked: Mar 17 '10 at 03:11 AM

Seen: 1150 times

Last Updated: Mar 17 '10 at 03:11 AM