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 Liamh101 · Jan 19, 2013 at 09:35 PM · errormovementmaths

Mathematicle error help

I'm having a little issue tracking down a mathematical error in my script code. I've developed a simple script to move a cube around my map in a rectangular fashion, however when the cube finishes it circuit the cube ends up in a different position to where is started.

The cube starts on the z axis at 716.8967 and on the x axis at 672.9058. Then the cube moves across the z axis for 140 frames (going 5 on Vector3) then goes up on the x axis for 115 frames(speed stays the same). Then the opposite happens and the cube finishes at 716.1387 (z axis) and 671.6195 (x axis).

Could anyone help me understand where I lost 0.758 on the z axis and 1.2863 on the x axis. I've placed the code bellow (Don't ask about the names). Thank you!

    #pragma strict
     
     var x = 0;//x axis
     var z = 0;//z axis
     var R = true;//right
     var L = false;//left
     var U = false;//up
     var D = false;//down
     function Update () {
     
     if(R){
         //Makes Alan Rickman move along Z axis
         transform.Translate(Vector3(5,0,0) * Time.deltaTime);
         z++;
         Debug.Log("Alan is moving Right");
     
             if(z > 139){
             R = false;
             U = true;
             var gary = Resources.LoadAssetAtPath("Assets/Textures/garyoldman.jpg", Texture);
             renderer.material.mainTexture = gary;
             }
     }
     
     if(U){
         //Makes Alan Rickman move along X axis
         transform.Translate(Vector3(0,0,5) * Time.deltaTime);
         x++;
         Debug.Log("Alan should be moving up");
         
             if(x > 114){
             U = false;
             L = true;
             var Kevin = Resources.LoadAssetAtPath("Assets/Textures/kevin_spacey.jpg", Texture);
             renderer.material.mainTexture = Kevin;
             }
         }
         
          
 
 if(L){
 //Makes Alan Rickman move along Z axis
 transform.Translate(Vector3(-5,0,0) * Time.deltaTime);
 z--;
 Debug.Log("Alan is moving left");
 
     if(z < 1){
     L = false;
     D = true;
     var jackson = Resources.LoadAssetAtPath("Assets/Textures/jackson-main.jpg", Texture);
     renderer.material.mainTexture = jackson;
     }
 }
 
 if(D){
 //Makes Alan Rickman move along X axis
 transform.Translate(Vector3(0,0,-5) * Time.deltaTime);
 x--;
 Debug.Log("Alan Should be moving down");
 
     if(x < 1){
     D = false;
     R = true;
     var alan = Resources.LoadAssetAtPath("Assets/Textures/alan_rickman.jpg", Texture);
     renderer.material.mainTexture = alan;
     }
 }
 
 }

 
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Dave-Carlile · Jan 19, 2013 at 09:43 PM

You're multiplying the movement distance by Time.deltaTime.

 transform.Translate(Vector3(5,0,0) * Time.deltaTime);


This isn't a constant value, but rather the time the last frame took to update. So the amount you're moving isn't constant.

Trying using the FixedUpdate function rather than Update. That should give you a constant time.

Also, a better way to do this would be to decide the waypoints you want to use, then use Vector3.Lerp to move between them. That way you're absolutely guaranteed to always move to the same place each time.

Comment
Add comment · Share
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

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

10 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

Related Questions

Expecting ':' Found '=' Error 1 Answer

Error... that I don't understand. 3 Answers

Error with code, cannot figure out solution... 1 Answer

BCE0044: Expecting : Found = Error! 2 Answers

Expecting EOF Found } 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