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 CarlLawl · Jan 31, 2011 at 04:50 PM · mathdistancepercentage

Math - distance to percentage

Im trying to convert the percentage of a level and its completion based on distance to the end object So in each level there is a spawn point and an end point, ive got the distance between the player and the end point but Im struggling to work out a percentage?

Logically Im guessing itd be to get the distance between spawn and end as well as player and end then im stuck, would it be something like distance between spawn and end multiplied by 100 divided by distance berween player and end point then round it to the nearest int?

Any help appreciated, thanks

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

2 Replies

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

Answer by poncho · Jan 31, 2011 at 04:56 PM

well, you can have the distance from the spawn point and the object, then the distance from the spawn to the end lets call distancespawnobject and distancespawnend divide distancespawnobject / distancespawnend and the result multiplied by 100 or the 10 factor to make the result a number between 0-100

Comment
Add comment · Show 5 · 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 DaveA · Jan 31, 2011 at 05:02 PM 0
Share

(spawnToPlayer / spawnToEnd) * 100 will be a percent from 0.0 to 100.0

avatar image poncho · Jan 31, 2011 at 05:22 PM 0
Share

yeah but i had a problem like this when in ipad the values for some reason were scaled ins$$anonymous$$d of 1 was .001 an i had to add a 1000 factor to clean that mess XD thats why write "or the 10 factor to make the result a number between 0-100"

avatar image CarlLawl · Jan 31, 2011 at 05:58 PM 0
Share

is it possible to make paths and do it like that ins$$anonymous$$d? it seems to be going higher than 100% which i understand why, because youve gone passed the marker, so would it be possible to make a path and work out a percentage based on where you are on the path?

avatar image DaveA · Jan 31, 2011 at 06:24 PM 0
Share

What you might want to use the distance from the end point to the player rather than the spawnpoint to the player. This might result in negative numbers if they go in the opposite direction at the start, so just don't let it go below zero. Essentially, you'd be defining a circle around the end point with max radius the distance to the spawn point, anything more is 'out of bounds' and clamped to zero

avatar image poncho · Jan 31, 2011 at 06:24 PM 0
Share

if you are doing a 2d game, you can work with the x on perspective at your camera, y|x then you need to make a pathBeginX and pathEndX like pathBeginX |o_$$anonymous$$ pathEndX 0|object at 4 (7.5%) ---------------------|40 this way even if you are on x 4 but on y like 50 or something the "path" would say that you are on 7.5% of your path if this not help, please explain more

avatar image
0
Best Answer

Answer by yoyo · Jan 31, 2011 at 06:07 PM

If you don't want the complexity of paths, and you don't want the distance to go over 100% then use (100 * spawnToPlayer)/(spawnToPlayer + playerToEnd).

Comment
Add comment · Show 2 · 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 CarlLawl · Jan 31, 2011 at 07:39 PM 0
Share

basically, i have a game where you run around a circuit so i dont want it to be a straight line id actually need a path, ive thought about it a bit more and i think ill have to look into how paths work but thanks for everyones help

avatar image yoyo · Jan 31, 2011 at 09:25 PM 1
Share

you could create an array of points scattered along the your level that trace out the path, then find which point the player is closest to and use that to deter$$anonymous$$e distance estimate

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

No one has followed this question yet.

Related Questions

How can I get the Time taken for the 2 moving objects to touch each other 2 Answers

Finding Nearest Object Both Positive And Negative? 1 Answer

Simple Maths Problem (I Suck At Maths) 2 Answers

How to move slider same amount with different max values when moving it by a percentage Unity 1 Answer

How can I have a distance between 2 points = 0-1 (min = 0, max = 1) and in between is a decimal? [C#] 2 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