car water floating script help.

hi i have part of a script:

for(i=0;i<wheels.length;i++){
            if(water){
            if(wheels*.transform.position.y < waterLevel){*
 *rigidbody.drag = .1;*
 <em>var newVector = Vector3(meshWheels_.transform.position.x,waterLevel,meshWheels*.transform.position.z);*_</em>
 <em><em>_var wheelsDistance = Vector3.Distance(meshWheels*.transform.position,newVector);*_</em></em>
 <em><em>_*var moveVector = Vector3(0, wheelsDistance, 0);*_</em></em>
 <em><em>_*if(wheelsDistance >0){*_</em></em>
 <em><em><em>_rigidbody.AddForceAtPosition(moveVector,meshWheels*.transform.position);*_</em></em></em>
 <em><em><em>_*}*_</em></em></em>
 <em><em><em>_*rigidbody.drag = 2;*_</em></em></em>
 <em><em><em>_*rigidbody.mass = 1;*_</em></em></em>
 <em><em><em>_*rigidbody.useGravity = false;*_</em></em></em> 
 <em><em><em>_*}*_</em></em></em>
 <em><em><em>_*else{*_</em></em></em>
 <em><em><em>_*rigidbody.useGravity = true;*_</em></em></em>
 <em><em><em>_*rigidbody.mass = 5000;*_</em></em></em>
 <em><em><em>_*}*_</em></em></em>
 <em><em><em>_*}*_</em></em></em>
 <em><em><em>_*}*_</em></em></em>
<em><em><em>_*```*_</em></em></em>
<em><em><em>_*<p>and it is supposed to make the car float when under the waterLevel. but it is also supposed to make the car stay up straight..... because it adds force at the position of each wheel with the power of the force being the distance from that wheel when in the water. but it dosn't.</p>*_</em></em></em>
<em><em><em>_*<p>any help would be awesome.</p>*_</em></em></em>

if you want it to lay on the water.. so that its roof is facing directly up, just get the Up vector, and ensure its facing Up in world space.. just do some rotations based on the difference from the worlds up matrix, and the vehicles up matrix.. might have some funny transitions, but thats just a quick fix I'd do..

if I understand what you're expecting at least.. I'm to tired to really help out with the maths atm though.. but good luck!

I usually find force problems having no noticable effect like this is down to a matter of magnitude. As cncguy suggested, perhaps it's worth putting a multiplier on your force, eg.

var moveVector = Vector3(0, wheelsDistance * multiplier, 0);

where "multiplier' is a var you set earlier, to something like 10 or 100. If it goes mental, no worries, at least it's making a difference. Tweak as necessary :)

You could also try changing the force type to Acceleration or other, as the last argument when calling AddForceAtPosition. Check out the various types of forces here.