I have an rigidbody with freezeRotation=true.
A mesh is parented to this rigidbody, and I want this mesh to rotate based on the velocity of the rigidbody. This means: if the rigidbody is moving upwards,
the mesh should face upwards (its a piranha :-))
Another option: how do I put the ‘weight’ of the rigidbody at the bottom so that it will ‘want’ to point down in physics?
If you normalize the velocity vector you will be left with a direction with the origin at the object’s center. The magnitude of that vector is the speed to go in that direction.
You could check that vector against an up vector (0,1,0) aka Vector3.up using the vector angle functions perhaps and if the angle is low, you’re up. I haven’t thought that through yet though.
Hope that helps a bit… Sry it’s so vague, in a bit of a hurry.
I assume you are accelerating the piranha by adding forces to the rigidbody (ie, as opposed to having a fish that is constantly pushed around by collisions)?
The Rigidbody class has a method called AddForceAtPosition. This allows you to push the object at a point away from its centre of mass. Try adding a force to your fish slightly in front of its centre of mass in the direction you want it to start moving - it should first point in the right direction and then start moving in that same direction.
You can do the same with the “weight at the bottom” thing. Gravity will act on the fish through its centre of mass. You just need to add the buoyancy force to a position slightly upward of the COM to make it float upright.