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 /
avatar image
0
Question by rowanabejjani · Jul 25, 2013 at 11:23 AM · androidmoving3dobject

Why my 3dobject not moving correctly in the right direction

I have this script but my 3dobject (skier) not moving correctly in the right direction when i tilt my android, and i cannot find where the problem is!!

  if(cacheMagnitude240)
     {
     if(fixedAcceleration.y<0)
         {
         ok=false;
         }
     }
 if(transform.eulerAngles.y<140)
     {
     if(fixedAcceleration.y>0)
         {
         ok=false;
         }
     }
     grounded=wheel.GetGroundHit(outHit);
 if(grounded==false)
     {
     ok=false;
     timeCache=Time.time;
     cScript.setX();
     if(processedX2==false)
         {
         trailParticle.emit=false;
         audio.Pause();
         ok2=false;
         processedX2=true;
         processed=false;
         
         }
     }
 else
     {
     if(processed==false)
         {
         if(secObj.transform.localRotation.eulerAngles.y<300&&secObj.transform.localRotation.eulerAngles.y>60||playing==false)
             {
             secObj.transform.localRotation.eulerAngles.y=0;
             doRagdoll();
             }
         trailParticle.emit=true;
         audio.Play();
         cScript.resetX();
         processedX2=false;
         processed=true;
         trickType=-1;
         ok2=true;
         }
     }
     
 if(cacheMagnitude>3)
     {
     audio.volume=cacheMagnitude/40;
     trailParticle.minEmission=cacheMagnitude*3;
     trailParticle.maxEmission=cacheMagnitude*5.5;
     
     if(ok==true)
         {
         if(Mathf.Abs(fixedAcceleration.y)>0.11)
         {
         wheel.steerAngle =1/(cacheMagnitude/4)*fixedAcceleration.y*turnProgression*Time.deltaTime;
         rigidbody.AddRelativeTorque (Vector3.up * fixedAcceleration.y*turnProgression*2*Time.deltaTime);
         }
         
     if(ok2==true)
         {
         if(fixedAcceleration.y<-0.11)
             {
             animationComp.CrossFade("CarveRight",0.35);
             
             }
         else if (fixedAcceleration.y>0.11)
             {
             animationComp.CrossFade("CarveLeft",0.35);
             
             }
         else if(cacheMagnitude>(maxSpeed/2))
             {
             animationComp.CrossFade("Fast",0.8);
             }
         else
             {
             animationComp.CrossFade("Ski",0.8);
             }
         }
     }
 }
 else
     {
      if(Mathf.Abs(fixedAcceleration.y)>0.11)
         {        
         rigidbody.AddRelativeTorque (Vector3.up * fixedAcceleration.y*turnProgression*4*Time.deltaTime);
         }
     animationComp.CrossFade("idle",0.2);
     }
 }
 function getWeight(acceleration:float):float
     {
     acceleration=Mathf.Abs(acceleration);
     if(acceleration<2.1)
         {
         return (2.1-acceleration)*100;
         }
     return 100;
     }
 
 function CalibrateAccelerometer () {
     var accelerationSnapshot : Vector3 = Input.acceleration;
     var rotateQuaternion : Quaternion = Quaternion.FromToRotation (new Vector3 (0.0, 0.0, -1.0), accelerationSnapshot);
     calibrationQuaternion = Quaternion.Inverse (rotateQuaternion);
 }
Comment
Add comment · Show 4
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 dorpeleg · Jul 25, 2013 at 11:39 AM 1
Share

No one is going to read this...

Please format your code correctly and reduce the code to relevant parts only.

avatar image Benproductions1 · Jul 25, 2013 at 11:19 PM 0
Share

Oh GOD that unreadable indentation. Code like this makes me cry :(

avatar image ikelaiah · Jul 26, 2013 at 12:02 AM 0
Share

@rowanabejjani, you mentioned "...i cannot find where the problem is!!" Your code was hard to follow. It is a good practice before doing a any coding to get a clear picture of what you are doing. $$anonymous$$ake a plan. For example, do A, then B, if fails, do C. Then translate these steps in a readable code. If necessary use comments. I doubt you were able to follow your own code. Writing code is an art, just like cooking, gardening or brick-laying.

Don't be discouraged, I am learning too. Often, like a soccer ball, we need to be kicked around (too often) to achieve our goal.

avatar image dan19 · Jul 29, 2013 at 11:41 AM 1
Share

Na$$anonymous$$g your variables "ok" and "ok2" is not ok.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How do I set my android app to landscape mode entirely? 1 Answer

if moving statement 1 Answer

Facebook unity sdk: is it possible to send friend invites/app requests to non app users ? 1 Answer

Issue Building my Video scene to Android 1 Answer


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