Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jun 03, 2013 at 04:38 AM by robertbu for the following reason:

Other

avatar image
0
Question by lukejaparidze · May 30, 2013 at 11:20 PM · androiderrorjavapro

Boat script problems when changing platform to android

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<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="";
 }
 
 @script RequireComponent (AudioSource)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image lukejaparidze · May 30, 2013 at 11:16 PM 0
Share

oh and its not really my script, i just put in the parts for the touch control

avatar image Benproductions1 · Jun 03, 2013 at 01:37 AM 0
Share

You should declare the type of your variables.
Also I think people could actually help you if you posted the errors, rather than just saying you get them!

avatar image robertbu · Jun 03, 2013 at 04:38 AM 0
Share

UA is to help you understand your specific technical problems so you can solve your own problems. It is not for us to do your work for you by debugging a script largely written by someone else for you.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

ClassNotFoundException on UnityPlayerProxyActivity on some devices 0 Answers

Accessing and using Javaclasses from Unity 1 Answer

erorr in building scene ????? 0 Answers

Error Building Android Project 2 Answers

Error Building Player: 'aapt.exe' Win32Exception 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges