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.
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.
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.
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 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!
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…
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.
– Jean-Fabre