void FixedUpdate() { Vector3 p = transform.position; float waterHeight = ocean.GetHeightAtLocation(p.x, p.z); Vector3 waterNormal = ocean.GetNormalAtLocation(p.x, p.z); if (transform.position.y > waveEffectDepth) { waterNormal = Vector3.Lerp(waterNormal, Vector3.up, .5f); } else { waterNormal = Vector3.up; } float forceFactor = Mathf.Clamp(1f - (p.y - waterHeight) / MaxDistance, 0, 1); transform.parent.GetComponent <Rigidbody>().AddForceAtPosition(waterNormal * forceFactor * LiftAcceleration * Body.mass, p); //if (!Debug.isDebugBuild) // return; Debug.DrawLine(p, p + waterNormal * forceFactor * 5, Color.green); Debug.DrawLine(p + waterNormal * forceFactor * 5, p + waterNormal * 5, Color.red); }
void FixedUpdate() { Vector3 p = transform.position; float waterHeight = ocean.GetHeightAtLocation(p.x, p.z); Vector3 waterNormal = ocean.GetNormalAtLocation(p.x, p.z); float forceFactor = Mathf.Clamp(1f - (p.y - waterHeight) / MaxDistance, 0, 1); //transform.parent.rigidbody.AddForceAtPosition(waterNormal * forceFactor * LiftAcceleration * Body.mass, p); thisBody.AddForceAtPosition(waterNormal * forceFactor * LiftAcceleration * Body.mass, p); if (!Debug.isDebugBuild) { return; } Debug.DrawLine(p, p + waterNormal * forceFactor * 5, Color.green); Debug.DrawLine(p + waterNormal * forceFactor * 5, p + waterNormal * 5, Color.red); }