I have s imply bouyancy script for floating objects. I pilfered it from somewhere, but it’s just a simple application of force at the point of bouyancy. I’m trying to apply multipl point of bouyancy, to simulate real objects. However, regardless of the offset points i put in, it alway defaults to 0,0,0. Specifically, the debug log for iteratebuoyancypoints shows the correct points, but when they are passed to applybouyancy, they’re all converted to 0,0,0.
I don’t have a clue how or why this could be happening, and I’ve played about a lot, with the code. i’m sure it’s something simple I’m missing, but can anyone see it?
using UnityEngine;
using System.Collections;
public class Floater : MonoBehaviour {
public float waterLevel, floatHeight;
private Vector3 buoyancyOffset;
public Vector3[] buoyancyOffsets;
public float bounceDamp;
public Vector3 massCentre;
public Rigidbody rb;
Color color;
void Start(){
rb = GetComponent<Rigidbody>();
rb.centerOfMass = massCentre;
}
void FixedUpdate () {
IterateBuoyancyPoints (buoyancyOffsets);
}
public void AddBuoancyPoint(){
}
public void RemoveBuoancyPoint(){
}
private void IterateBuoyancyPoints(Vector3[] buoyancyOffsets){
for(int i = 0; i < buoyancyOffsets.Length; i++){
if(i==0){color = Color.red;} else if(i==1){color = Color.blue;}else if(i==2){color = Color.green;};
ApplyBouancy(buoyancyOffsets*, color);*
_ Debug.Log (buoyancyOffsets*);_
_ }*_
* }*
* private void ApplyBouancy(Vector3 buoancyOffset, Color color){*
* Vector3 actionPoint = transform.position + transform.TransformDirection(buoyancyOffset);*
* float forceFactor = 1f - ((actionPoint.y - waterLevel) / floatHeight);*
* Debug.Log (buoyancyOffset);*
* if (forceFactor > 0f) {*
_ Vector3 uplift = -Physics.gravity * (forceFactor - GetComponent ().velocity.y * bounceDamp);_
* GetComponent ().AddForceAtPosition (uplift, actionPoint);*
* Debug.DrawRay (actionPoint, uplift, color, 10f);*
* }*
* }*