- Home /
Changing a rigidbody's center of mass, to get a natural rotation while it moves through the air
Hey folks. I'm trying to make an object similar to javelin, which rotates naturally as it flies through the air, as you'd expect from an object which has it's center of mass located in the tip.
Problem is, I'm not have any of my desired results from setting the centerOfMass variable in my object's rigidbody, which I assumed would do the trick. Perhaps I'm using it incorrectly?
any idea how i can accomplish this? I need the movement of this object to be perfect.
Could you share a sample project? that would help tweaking what you have. So many params comes into account, that it difficult to answer such question without a proper base.
Answer by efge · Mar 21, 2011 at 01:41 PM
You could also take a look at this answer: Realistic rotation of flying arrow?
That's a good link, too. The slerp solution doesn't seem so great, but the LookRotation (last entry) in this link should work. Just moving mass around isn't going to do much. The tail feathers of an arrow have much more to do with it arcing downward than mass placement. Drag is the key if you want to go the physics route, but coding is really the best (and least expensive) way to go.
And just as a thought, it would be nice if the Unity folks could make drag moveable like mass through code. Don't know if this is even possible, but it would be nice for flight sims etc. to be able to have greater air drag at one end of a rigidbody than the other without having to link a separate rigidbody with a joint. Just a wish, but not essential :)
You do not have to use a joint, just create empty game objects as children, attach rigidbodies and set different values for drag etc.
You might be right. Tried that in a flight sim a while back and it didn't work so well. I found that separate rigidbodies attached with fixed joints gave me more control and allowed me to apply physical forces on, for example, a plane wing, that I couldn't achieve by parenting. But for a javelin, parenting is worth a try. Would certainly be simpler!
Forgot to reply! sorry all. yeah, the LookRotation in the last entry of that post was the most effective and easy solution for this problem. Thanks a lot!
Answer by Skjalg · Mar 21, 2011 at 09:53 AM
Make a gameobject that has your rigidbody attached to it, with its center of mass in the middle. Then create a child gameobject and attach your javelin model to that and offset it correctly so that the parent gameobject is close to the tip.
That should make it work as you intend :)
Answer by tool55 · Mar 21, 2011 at 01:32 PM
Here's a link to a similar thread:
http://forum.unity3d.com/threads/22063-I-shot-an-arrow-up-in-the-air...?highlight=shooting+arrow
Personally, I would code the rotation using LookAt as GargarathSunman suggests in this link, but if you want to do it with physics, you'll probably need to build the javelin in at least a couple of parts, as the others suggest in the link, and add different drag and angular drag values to each part,perhaps density as well. If you threw a javelin in a vacuum, it would never land point down because air drag plays such an important part (all things fall at the same rate regardless of mass, thank you Sir Isaac Newton). It's a difficult simulation for the physics engine to get right.
Answer by alcatraz5 · Apr 30, 2014 at 12:53 PM
Fixed -create a empty game object -than add your movement script to it -delete remove the movement script from the javelin game object, if any but keep the rotation script -drag javelin game object to the new game object just created......
Your answer
Follow this Question
Related Questions
Problem with Rigidbody.CenterOfMass 2 Answers
How can I rotate around with a Rigidbody while respecting physics? 0 Answers
AddRelativeTorque() Applied Incorrectly When Using a Custom Centre of Gravity 0 Answers
AddRelativeTorque results in incorrect angular acceleration (Maybe centrifugal force affects) 0 Answers
Is there a way to draw center of mass on the screen? 1 Answer