why does my boat sink

hello all

i have made a boat level, where you steer a boat around a level, i had it working but then i did some thing to the JitReceive or the boat script, (not sure what i did)
but my boat just sinks now.

i am using max msp to control the boat,
however on the boat pre fab there is motor and steer var which you can use to control the boat (for testing). i would be a shame if i had to abandon this project as it did work, i have spend 3 days trying to get it back but with no success
i think it will be some thing simple in the scripts, as i dont known javascript very well

i have attached a link to mega uploader which is a pared down version of the game, please help

ps i try to upload it to the forum but just got this message
No post mode specified

thanks you
Ben

http://www.megaupload.com/?d=8MAWGDO8

You may get a faster responce if you post your code. cause downloading your project may detur those wanting to help on the fly.

using UnityEngine;
using System.Collections;
//Even though this script is in C# Its pretty easy to understand fron looking at it.
public class Floater : MonoBehaviour {
	public float waterLevel, floatHeight;
	public Vector3 buoyancyCentreOffset;
	public float bounceDamp;
	
	

	void FixedUpdate () {
		Vector3 actionPoint = transform.position + transform.TransformDirection(buoyancyCentreOffset);
		float forceFactor = 1f - ((actionPoint.y - waterLevel) / floatHeight);
		
		if (forceFactor > 0f) {
			Vector3 uplift = -Physics.gravity * (forceFactor - rigidbody.velocity.y * bounceDamp);
			rigidbody.AddForceAtPosition(uplift, actionPoint);
		}
	}
}

This may be a quick Fix :smile:

thanks for you replay!

and thanks you for the code, however i am not sure where to edited in to my script, i have replaced it with my old code but the boat fell through the water.

here is the the code from the boat and JitReceive, the way it worked was:
the steer var and the motor var from the boatScript are control by the JitReceive Script,

if you can help i would be every great full

thanks Ben

this is the boat script

//Mass
var mass = 3000;
//Force of the boats engine
var engineForce = 10000.0;
//Rudder torque coefficient for steering the boat
var rudder = 40;
//How far the direction of the propeller force is deflected by the rudder
var propellerTurningAngle = 20;
//drag coefficients along x,y and z directions
var drag = Vector3(6.0,4.0,0.2);
//angular drag coefficient
var angularDrag = 0.8;
//heigh of center of gravity
var cogY = -0.5;
//max width, height and length of the boat (used for water dynamics)
var size = Vector3(3,3,10);
//volume of boat in liters (the higher the volume, the higher the boat will floar)
var volume = 9000;


//particle system used for foam from the boat's propeller
var engineSpume : Transform;

var steer = 0.0;
var motor = 0.0;

private var queryUserInput = true;
private var rpmPitch = 0.0;
private var waterSurface = null;

function Start()
{
	//Destroy existing rigidbody, we don't want anyone to mess with it.
	if(rigidbody)
		Destroy(rigidbody);
	
	//setup rigidbody	
	gameObject.AddComponent(Rigidbody);
	rigidbody.mass = mass;
	rigidbody.angularDrag = angularDrag;
	rigidbody.centerOfMass.y = cogY;
	rigidbody.interpolation = RigidbodyInterpolation.Interpolate;
	
	//start engine noise
	audio.loop = true;
	audio.Play();
	
	//check for particle emitter
	if(engineSpume != null)
		if(engineSpume.particleEmitter == null)
		{
			Debug.Log("The Engine Spume GameObject needs to have a ParticleEmitter Component!");
			engineSpume = null;
		}
	
	if(GetComponentInChildren(Collider) == null)
		Debug.Log("The Boat needs a collider to float on the water!");
}

//Functions to be used by external scripts 
//controlling the boat if required
//===================================================================

//return a status string for the vehicle
function GetStatus(status : GUIText) {
	status.text="v="+(rigidbody.velocity.magnitude * 3.6).ToString("f1") + " km/h";
}

//return an information string for the vehicle
function GetControlString(info : GUIText) {
	info.text="Use arrow keys to control the boat.";
}

//Setup main camera to follow boat
function SetupCamera() {
	if(Camera.main.GetComponent(SmoothFollow) != null)
	{
		Camera.main.GetComponent(SmoothFollow).enabled=true;
		Camera.main.GetComponent(SmoothFollow).target=transform;
		Camera.main.GetComponent(SmoothFollow).distance=11;
		Camera.main.GetComponent(SmoothFollow).height=3;
	}
	Camera.main.transform.parent=null;
}

//Enable or disable user controls
function SetEnableUserInput(enableInput)
{
	queryUserInput=enableInput;
}

//Boat physics
//======================================================================

function FixedUpdate () {
	
	//if there is no water surface we are colliding with, no boat physics	
	if(waterSurface==null)
		return;

	//query input axes if necessarry
	/*motor = 0.0;
	steer = 0.0;
	if(queryUserInput)
	{
		motor = Input.GetAxis("Vertical");
		steer = Input.GetAxis("Horizontal");
	}*/
	
	netObj = GetComponent("JitReceive");
	motor = netObj.motor;
	steer = netObj.steer;


	//get water level and percent under water
	waterLevel=waterSurface.collider.bounds.max.y;
	distanceFromWaterLevel = transform.position.y-waterLevel;
	percentUnderWater = Mathf.Clamp01((-distanceFromWaterLevel + 0.5*size.y)/size.y);


	//Buoyancy (the force which keeps the boat floating above water)
	//--------------------------------------------------------------
	
	//the point the buoyancy force is applied onto is calculated based 
	//on the boat's picth and roll, so it will always tilt upwards:
	buoyancyPos=transform.TransformPoint(-Vector3(transform.right.y*size.x*0.5,0,transform.forward.y*size.z*0.5));
	
	//then it is shifted arcording to the current waves
	buoyancyPos.x+=waterSurface.waveXMotion1*Mathf.Sin(waterSurface.waveFreq1*Time.time)
				+waterSurface.waveXMotion2*Mathf.Sin(waterSurface.waveFreq2*Time.time)
				+waterSurface.waveXMotion3*Mathf.Sin(waterSurface.waveFreq3*Time.time);
	buoyancyPos.z+=waterSurface.waveYMotion1*Mathf.Sin(waterSurface.waveFreq1*Time.time)
				+waterSurface.waveYMotion2*Mathf.Sin(waterSurface.waveFreq2*Time.time)
				+waterSurface.waveYMotion3*Mathf.Sin(waterSurface.waveFreq3*Time.time);
	
	//apply the force
	rigidbody.AddForceAtPosition(- volume * percentUnderWater * Physics.gravity , buoyancyPos);
	
	//Engine
	//--------------------------------------------------------------
	
	//calculate propeller position
	propellerPos = Vector3(0,-size.y*0.5,-size.z*0.5);
	propellerPosGlobal=transform.TransformPoint(propellerPos);
	
	//apply force only if propeller is under water
	if(propellerPosGlobal.y<waterLevel)
	{
		//direction propeller force is pointing to.
		//mostly forward, rotated a bit according to steering angle
		steeringAngle = steer * propellerTurningAngle * Mathf.Deg2Rad;
		propellerDir = transform.forward*Mathf.Cos(steeringAngle) - transform.right*Mathf.Sin(steeringAngle);
		
		//apply propeller force
		rigidbody.AddForceAtPosition(propellerDir * engineForce * motor , propellerPosGlobal);
		
		//create particles for propeller
		if(engineSpume!=null)
		{
			engineSpume.position = propellerPosGlobal;
			engineSpume.position.y = waterLevel-0.5;
			engineSpume.particleEmitter.worldVelocity = rigidbody.velocity*0.5-propellerDir*10*motor+Vector3.up*3*Mathf.Clamp01(motor);
			engineSpume.particleEmitter.minEmission = Mathf.Abs(motor)*3;
			engineSpume.particleEmitter.maxEmission = Mathf.Abs(motor)*3;
			engineSpume.particleEmitter.Emit();				
		}
	}
	
	//Drag
	//--------------------------------------------------------------
	
	//calculate drag force
	dragDirection = transform.InverseTransformDirection(rigidbody.velocity);
	dragForces = -Vector3.Scale(dragDirection,drag);
	
	//depth of the boat under water (used to find attack point for drag force)
	depth = Mathf.Abs(transform.forward.y)*size.z*0.5+Mathf.Abs(transform.up.y)*size.y*0.5;
	
	//apply force
	dragAttackPosition = Vector3(transform.position.x,waterLevel-depth,transform.position.z);
	rigidbody.AddForceAtPosition(transform.TransformDirection(dragForces)*rigidbody.velocity.magnitude*(1+percentUnderWater*(waterSurface.waterDragFactor-1)),dragAttackPosition);
	
	//linear drag (linear to velocity, for low speed movement)
	rigidbody.AddForce(transform.TransformDirection(dragForces)*500);
	
	//rudder torque for steering (square to velocity)
	forwardVelo = Vector3.Dot(rigidbody.velocity,transform.forward);
	rigidbody.AddTorque(transform.up*forwardVelo*forwardVelo*rudder*steer);	
	
	//Sound
	//--------------------------------------------------------------
	
	audio.volume=0.3+Mathf.Abs(motor);

	//slowly adjust pitch to power input
	rpmPitch=Mathf.Lerp(rpmPitch,Mathf.Abs(motor),Time.deltaTime*0.4);
	audio.pitch=0.3+0.7*rpmPitch;

	//reset water surface, so we have to stay in contact for boat physics.
	waterSurface = null;
}

function OnTriggerStay(coll)
{
	if(coll.GetComponent(FloatableWater)!=null)
		waterSurface=coll.GetComponent(FloatableWater);
}

//Called by DamageReceiver if boat destroyed
function Detonate()
{
	//no more boat force => sink
	enabled=false;
	
	//Mark object no longer a target for homing missiles.
	if(tag=="MissileTarget")
		tag="";
}

//set speed
function setSpeed(pSpeed){
	speed = pSpeed;
}


// set motor
function setMotor(pMotor){
	motor = pMotor;
}


@script RequireComponent (AudioSource)

this is the JitReceive script

	// mu (myu) Max-Unity Interoperability Toolkit old2
// Ivica Ico Bukvic <ico@vt.edu> <http://ico.bukvic.net>
// Ji-Sun Kim <hideaway@vt.edu>
// Keith Wooldridge <kawoold@vt.edu>
// With thanks to Denis Gracanin

// Virginia Tech Department of Music
// DISIS Interactive Sound  Intermedia Studio
// Collaborative for Creative Technologies in the Arts and Design

// Copyright DISIS 2008.
// mu is distributed under the GPL license v3 ([url]http://www.gnu.org/licenses/gpl.html[/url])

using UnityEngine;
using System.Collections;
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;


public class JitReceive : MonoBehaviour {

	public int portNo;
	public int maxObjects;
	
	public float steer = 0.0f;
	public float motor = 0.0f;

	//struct for pointing to various objects
	private struct objectList {
		public string objName;
		public GameObject objPointer;
		
		public void set(string s, GameObject gp) {
			objName = s;
			objPointer = gp;
		}
	}
	private int numObjects;
	private objectList[] o;
	
	//custom calls pointer
	JitCustomEvents jitCustom;
	
	private TcpClient incoming_client;
	private NetworkStream netStream;
	private TcpListener server;
	private bool waiting;

	// Use this for initialization
	void Start () {
		print ("hello world");
		if (portNo == 0) portNo = 32003;
		if (maxObjects == 0) maxObjects = 1024;
		waiting = false;
		server = new TcpListener(IPAddress.Any, portNo);
		server.Start();
		numObjects = 0;
		o = new objectList[maxObjects];
		jitCustom = (JitCustomEvents)GetComponent("JitCustomEvents");
	}
	
	// Update is called once per frame
	void Update () {
		
		string s;
		string[] values;
		
		if (server.Pending()) {
			incoming_client = server.AcceptTcpClient();
			netStream = incoming_client.GetStream();

			waiting = true;
		}
		while (waiting  netStream.DataAvailable) {
			try {
				int numread = 0;
				byte[] tmpbuf = new byte[1024];
				numread = netStream.Read(tmpbuf, 0, tmpbuf.Length);

				s = Encoding.ASCII.GetString(tmpbuf, 0, numread);
				s = s.Replace("\n","");
				values = s.Split(';');
							print("recd");

				if (values.Length > 1) {
					for (int i = 0; i < (values.Length-1); i++) {
						Parse(values[i]);
					}
				}
				else Parse(values[0]);
			}
			//Called when netStream fails to read from the stream.
			catch (IOException e) {
				waiting = false;
				netStream.Close();
				incoming_client.Close();
			}
			//Called when netStream has been closed already.
			catch (ObjectDisposedException e) {
				waiting = false;
				incoming_client.Close();
			}
		}	
	}
	
	void Parse(string toParse) {

		GameObject target = null;
		int i;
		bool found = false;
		
		string[] values = toParse.Split(' ');

			 target = GameObject.Find("BoatScript");
		
         //Component otherscript = GetComponent("BoatScript");
		//if (!target) {
		//	print("Requested object  not found.");
		//}
		else {
			switch (values[0]) {
				case "turn":
					//target.transform.Rotate((float)System.Convert.ToDouble(values[1]), 0 , 0);
					steer = (float)System.Convert.ToDouble(values[1]);
					break;
				case "accel":
				print("accel");
					//target.transform.Rotate(0,(float)System.Convert.ToDouble(values[1]) , 0);
					// Component otherscript = GetComponent("BoatScript");
				motor = (float)System.Convert.ToDouble(values[1]);
					break;
				case "reset":
				print("working?");
					break;
			
			}
		}
	}
/// new code ben

//stop of new coide ben


// not called from here
	void custom(GameObject tgt, string method, string[] val) {
		int sz = val.Length;
		float[] param = new float[sz];
		for (int i = 0; i < val.Length; i++) {
			param[i] = (float)System.Convert.ToDouble(val[i]);
		}
		jitCustom.run (tgt, System.Convert.ToInt32(method), param);
	}

	void scale(GameObject tgt, string xVal, string yVal, string zVal) {
		Vector3 newScale = new Vector3((float)System.Convert.ToDouble(xVal),
			(float)System.Convert.ToDouble(yVal), (float)System.Convert.ToDouble(zVal));
		tgt.transform.localScale += newScale;		
	}

	void absoluteScale(GameObject tgt, string xVal, string yVal, string zVal) {
		Vector3 newScale = new Vector3((float)System.Convert.ToDouble(xVal),
			(float)System.Convert.ToDouble(yVal), (float)System.Convert.ToDouble(zVal));
		tgt.transform.localScale = newScale;
	}

	void reposition(GameObject tgt, string xLoc, string yLoc, string zLoc) {
		Vector3 newLoc = new Vector3((float)System.Convert.ToDouble(xLoc),
			(float)System.Convert.ToDouble(yLoc), -(float)System.Convert.ToDouble(zLoc));
		tgt.transform.position = newLoc;
	}
	
	void move(GameObject tgt, string xVal, string yVal, string zVal) {
		tgt.transform.Translate((float)System.Convert.ToDouble(xVal), 
			(float)System.Convert.ToDouble(yVal), -(float)System.Convert.ToDouble(zVal));
	}
	
	void rotate(GameObject tgt, string xVal, string yVal, string zVal) {

		tgt.transform.Rotate((float)System.Convert.ToDouble(xVal), 
			(float)System.Convert.ToDouble(yVal), (float)System.Convert.ToDouble(zVal));
	}
	
	void absoluteRotate(GameObject tgt, string xVal, string yVal, string zVal) {
		float toX = (float)System.Convert.ToDouble(xVal);
		float toY = (float)System.Convert.ToDouble(yVal);
		float toZ = (float)System.Convert.ToDouble(zVal);
		Quaternion rot = Quaternion.identity;
		rot.eulerAngles = new Vector3(toX, 180-toY, toZ);
		tgt.transform.rotation = rot;
	}
}

got it sorted!!

it was

var steer = 0.0;
var motor = 0.0;

had to take them out, just got to do a reset now! then its finnish, my first game