Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 khuram_abstron · Jul 30, 2018 at 04:59 AM · positionwaypointscheckpointraceprogress bar

How to add progress bar showing player movement from start to finish line in 3d game ?,

I have added progress bar which is working fine for straight path. but in curve path as shown in figure the progress bar starts moving backwards due to decrease in z position of car. I have added many check point to calculate the distance between them and added them. but issue with current position. how to manage current position of car and move the progress bar.

 public Transform LevelEndCheckpoint;
 public Slider ProgressSlider;
 private float totalDistance,current_position,playerPosition;
 // Use this for initialization
 void OnEnable () {
     playerPosition = this.transform.position.z;
     //totalDistance = LevelEndCheckpoint.transform.position.z -  playerPosition;
             for (int i = 0; i < p_Length; i++) {
         totalDistance += Vector3.Distance( AllPoints [i + 1].position , AllPoints [i].position);
     }
     ProgressSlider.maxValue = -totalDistance;
     ProgressSlider.minValue = -playerPosition;
 }
 void Update () {
     playerPosition = -this.transform.position.z;
     ProgressSlider.value = playerPosition;
 }


![alt text][1] ![alt text][2] [1]: /storage/temp/121792-screenshot-10.png [2]: /storage/temp/121793-screenshot-11.jpg

,

screenshot-10.png (485.0 kB)
screenshot-11.jpg (283.1 kB)
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
0

Answer by madks13 · Jul 30, 2018 at 09:20 AM

Umm, since your game seems to be a racing game, why not have a simple float as the remaining distance and display that as a progress bar? For circular tracks, you can calculate the total distance, then calculate the remaining by substracting the distance covered.

Edit : to be clear, i'm not talking abour the distance covered by the car, but the track distance covered. You could have a car spin around and go backwards, the distance covered by the car would easily be greater than the total track length. Have to calculate the track distance covered by the car.

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 tormentoarmagedoom · Jul 30, 2018 at 10:13 AM 0
Share

But if the car goes back, what then? I think the best is to have so many checkpoints, like 100, so you can easy track the relative position in the race track.

Bye

avatar image madks13 tormentoarmagedoom · Jul 30, 2018 at 11:45 AM 0
Share

I never said not to use checkpoints. I only said to measure the track length. For that, you CAN use checkpoints. Let's say you have 100 checkpoints. On the progress bar, you would add 1% for each checkpoint done. If the car goes back, it won't register since once a checkpoint is passed you would deactivate it, only going further would continue the count. Also, you might want to activate only the next checkpoint to go to, since in a circular track one would be able to just go backwards and finish the race instantly.

In any case, the way you calculate the length of a track and the remaining distance to do is not really important. From OP's description, it seems coordinates are used currently, and that is not track length. Hence my suggestion to switch to track length and remaining distance.

avatar image khuram_abstron · Jul 31, 2018 at 04:20 AM 0
Share

I have used 30 trigger colliders to calculate the length of track. the length is calculated accurately. problem with car position. if i move progress bar with trigger position with collider it is not moving smooth i.e the progress bar stops until we hit the collider. and for passing current z position to the progress bar there is issue in curve path. the progress bar moves backward on turning due to decrease in z position. I actually want a progress bar which move continually with the player movement either it is straight path or a curve... Thank for showing your interest

avatar image madks13 khuram_abstron · Jul 31, 2018 at 08:05 AM 0
Share

Thought so. Unfortunately, the only thing i can think of, due to my lack of experience in racing games, is using large colliders. Each piece of the track would have a collider covering all of the usable area (the terrain the car can go on), then either in Update or FixedUpdate, check per section car position. That way you would be able to use local coordinates to know how much a car has moved and in which direction. That way you might even know when it's going backwards. Since this would need to be applied to each section, you would actually just need one script to do a check for the object it's attached to. So you could use a var that says how much of the section was covered by the car. Then you can have another script that has an ordered list of sections, and it will check for each section which car has advanced how much.

avatar image Sonky108 khuram_abstron · Jul 31, 2018 at 08:34 AM 0
Share

Using checkpoints you can store the last checkpoint and find next one. Having distance between both and knowing car's position you can "fake" continuous progress.

Another solution could be using Bezier curve(s). You should define your track as Bezier curve (or set of them), then you will be able to find car position on the track by casting actual car position. After all, you can compute distance between projected point and the end of the track: I think that's the approach for racing games. Check the link:

Other solution I can think about is to use built-in Nav$$anonymous$$eshAgent. It has remainingDistance, but I'm not sure if it will work without setting the position using Nav$$anonymous$$esh.

http://steve.hollasch.net/cgindex/curves/cbezarclen.html

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

109 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 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 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 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 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 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

Setting up player positions in a racing game 1 Answer

help with checkpoint sytem C# 2 Answers

Progress bar for player progress is backwards 1 Answer

I need help with a Text Location script (Ho bisogno di aiuto con uno script di posizione del testo) 0 Answers

Logic on calculating positions in a race. 5 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