Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Boat script problems when changing platform to android

$
0
0
OK so Ive been working on some kind of boat android project thingy. i have unity remote on my galaxy s3 so instead of building and deploying the app i would just run it like that. but i kept the platform on PC. the script worked perfectly and the touch controls were decent. but when i change the platform to android i get a sea of errors. i fixed some of them simply by putting a var before some lines but the others i cant fix. can you please correct the errors in my script. thanks in advance. PS: i would put the error codes in but there's so many of them i don't know where to start. if you all have unity pro and a at least basic android license please give it a try to see all of the errors. //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 throttle : GUITexture; var reverse : GUITexture; var left : GUITexture; var right : GUITexture; 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; for (var touch : Touch in Input.touches) { if (touch.phase == TouchPhase.Stationary && throttle.HitTest (touch.position)) { motor = 1; } else if (touch.phase == TouchPhase.Ended && throttle.HitTest (touch.position)) { motor = 0; } if (touch.phase == TouchPhase.Stationary && reverse.HitTest (touch.position)) { motor = -.5; } else if (touch.phase == TouchPhase.Ended && reverse.HitTest (touch.position)) { motor = 0; } if (touch.phase == TouchPhase.Stationary && left.HitTest (touch.position)) { steer = -1; } else if (touch.phase == TouchPhase.Ended && left.HitTest (touch.position)) { steer = 0; } if (touch.phase == TouchPhase.Stationary && right.HitTest (touch.position)) { steer = 1; } else if (touch.phase == TouchPhase.Ended && right.HitTest (touch.position)) { steer = 0; }} //if(queryUserInput) //{ //motor = Input.GetAxis("Vertical"); //steer = Input.GetAxis("Horizontal"); //} //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 sink enabled=false; //Mark object no longer a target for homing missiles. if(tag=="MissileTarget") tag=""; } @script RequireComponent (AudioSource)

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>