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 wenhua · Feb 06, 2012 at 06:02 AM · distance

Vector3.Distance function unclear

when i display it out, i thought starting distanceTravelled should be 0 why is it 15.02341 ???? can any1 help me out thx as starting its not moving, so it should be 0, so when i make it move then it increase distance travelled..

 var distanceTravelled :float = 0;

 var lastPosition: Vector3;

 var cube :Transform;

 function Start(){

    lastPosition = cube.tranform.position;
 }

 function Update(){

    distanceTravelled += Vector3.Distance(cube.transform.position,lastPosition);


     lastPosition = cube.transform.position;

}

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 flamy · Feb 06, 2012 at 07:01 AM 0
Share

change the start function to awake and try? well im not sure jus a suggestion! other than that everything seems perfect.

avatar image wenhua · Feb 06, 2012 at 07:52 AM 0
Share

no use ,nothings happened, start still straight away get a large distance Travelled value. think my x.y.z is large also.. so anyway to solve this.

avatar image flamy · Feb 06, 2012 at 12:31 PM 0
Share

is the value of distance being changed anywhere else?? ma be tht is the problem

avatar image wenhua · Feb 08, 2012 at 06:18 AM 0
Share

no, i think it should be this link causeing it distanceTravelled += Vector3.Distance(cube.transform.position,lastPosition);

o yea if i put the cube at tansform x-0,y-0,z-0, then the distantravelled = starting=0. but if starting i not put the cube at 0 i will have value, so how to solve it if i want it starting be 0 in the same time the cube is not at transform-0

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Berenger · Feb 06, 2012 at 06:55 AM

Is that cube moving ? You could try to get the distance yourself, [AB] = (B - A).magnitude

Comment
Add comment · Show 1 · 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
avatar image wenhua · Feb 06, 2012 at 07:15 AM 0
Share

no matter its moving or not, once start it will show distance with some value which is not suppose to be. as once start it show slowly from 0 and increase. any1 know how to do that??

avatar image
0

Answer by CgShady · Feb 13, 2012 at 09:06 AM

Try replacing

 lastPosition = cube.tranform.position;

with

 lastPosition = cube.transform.position;

I'm actually surprised it didn't stop with an error.

Comment
Add comment · Show 3 · 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
avatar image flamy · Feb 13, 2012 at 09:13 AM 0
Share

both seems same to me =/

avatar image wenhua · Feb 13, 2012 at 09:16 AM 0
Share

yea changed,the distanced travelled show =15.+ . but starting i wanted it to be 0,if it move then start ++. starting is show value due to the oject is placing at some coordinates. if its placing at coordinate=0 then start will =0. but i need to places it far away from coordinates 0

avatar image wenhua · Feb 13, 2012 at 09:31 AM 0
Share

somehow i think this calculation is not i wanted ^^as i need as in example: like if car didnt move distance =0 right, if it start moving how do i calculate its total distance travelled and if stop distance stop adding.somethings like this

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

7 People are following this question.

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

Related Questions

Maintain height/Altitude/distance from ground? 2 Answers

Animation / Distance 0 Answers

Why this script is not working? 1 Answer

Distance betwen two objects.Error,bug,etc. 2 Answers

How do I set a maximum distance on an activate-able object? 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