Getting 'bouyancy' on water to work. Help!
Hi! Before I start explaining, I've to say that I've searched everywhere I could, without results. I know this is an old treat, all the object-water-bounce things, but I just can't make it work. I hope you could help me.
I have this:
Rigidbody go_RB = GetComponent<Rigidbody>();
actionPoint = transform.position + transform.TransformDirection(transform.position / 2.5f);
forceFactor = 1f - ((actionPoint.y - water.transform.position.y) / floatHeight) * bounceDamp;
if (forceFactor > 0f)
{
uplift = (-Physics.gravity * (forceFactor - go_RB.velocity.y * bounceDamp)) * (go_RB.mass / 2);
go_RB.AddForceAtPosition(uplift, actionPoint);
}
As you can see, I've modded it a little to just bounce until the force 'has gone' (alas, I don't know if I'm doing it the right way, but It worked as expected) . Running at OnCollisionStay and TriggerStay, to execute the code depending if the collider is trigger or not, I also check if the collision object is water or not using tags. The water object have a box collider to avoid the object 'got out' the water if it falls too deep in it, in response to a high-place fall or a high-speed entry to water.
Everything works fine... except that it only do on one single object: the player.
I've tried everything I know (that's not much although), adding the script to the water so, using TriggerEnter and exit, lists all the objects ON the water so I can apply physics only to the objects on the water; also, I've tried attaching the script to each floating object in editor, just in case that didn't work as it have to; and also I've tried attaching the script to every object colliding with the water at run-time... but the result is the same: only the player can float on the water.
I've checked if it's a component lack, as to say "God! I've forgotten to attach a rigidbody, how dumb." or if the script it's not really attached, but no, unfortunately not. I've a rigidbody attached to every single object I wanted to float on water. I've attached the necessary colliders, an so on.
The only difference between the player and a single box (the thing I just can't make float) is that it can move with the axis input and has many colliders. As it is a horse and need to have a precise collision in unity 5, I've attached more than one single collider, so the legs, head and body have their own colliders. It worked just fine in movement and physics thing.
What the heck could I be doing wrong with that single box? it just fall deep on the water, no matter how I mod the rigidbody properties or scale.
Pleas help! I'm so tired and annoyed ... Thanks in advance.
Pd. : If someone needs more information, just ask! I'll post every single line of code and explain it if you need, maybe it could help someone else to improve this water-thing.