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 sethuraj · Feb 11, 2014 at 05:03 PM · errorinfiniterunnerfloatingpoint

Infinite runner world creation

Hey people,can someone help me on scripting this.I'm doing this like subway surfer,keeping player stationary and moving the world around him.My question is how can i instantiate the track prefab continuously right after previous one..?

alt text

For instance I have track named Track_A as prefab and as soon as this track is instantiated in the world, a script attached to it will make it move.I instantiate 5 prefabs at start-up one after another tailing perfectly.

When the first track is destroyed after reaching a certain point,it will get destroyed and a new track will be instantiated at the end of the chain but will cause FLOATING POINT PRECISION ERRORS leaving small gap between track prefabs.HOW CAN I SOLVE THIS..?

I am attaching the script with this

TrackScript

 //The length of the track (will be predefined and same for all track)
 public float tracklength=10;
 //The speed at which the tracks are moving
 private float worldspeed=10.0f;
 
 void Update()
 {
     //Move the new track towards the camera
     transform.translate(-Vector3.forward*Time.deltatime*worldspeed);
 }
 
 //Function to get the end of this track to create the next track
 public Vector3 GetTrackEndPos()
 {
     Vector3 Endposition=transform.position;
     Endposition.z+=tracklength;
     return Endposition;
 }
 

WorldScript

 //This function will be called when a track at player end is destroyed to create a new track ahead of the last track
 public void CreateOneTrackAhead()
 {
     if(LastTrackPrefab)
     {Pos_TrackInstantiate=LastTrackPrefab.GetComponent<TrackScript>().GetTrackEndPos();}
 
     //Instantiate the track at the end of previous track
     LastTrackPrefab=Instantiate(TrackPrefab,Pos_TrackInstantiate,Quaternion.identity);        
 }

preview.jpg (43.3 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

2 Replies

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

Answer by iamvishnusankar · Feb 11, 2014 at 07:51 PM

alt text

Use two cubes for each track; one as entry trigger and one as exit trigger "AND TURN OFF MESH RENDERING " to make the cube invisible on scene. Loop the sequence as shown in picture.

The reason exit trigger of Track A is set to the middle of Track B is to avoid the viewing problem. As it may leave a gap on destroyed area which might be annoying to viewer

Credits : MS Paint :D :D

void OnTriggerEnter(collider other)

{

//logic to instantiate the next track

}

void OnTriggerExit(collider other) {

//logic to destroy the previous track }


untitled.png (41.6 kB)
Comment
Add comment · Show 6 · 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 sethuraj · Feb 12, 2014 at 06:42 AM 0
Share

thanks.i will give it a try and let u knw.. :-)

avatar image sethuraj · Feb 12, 2014 at 10:43 AM 0
Share

Thanks for ur reply.Your solution was not exactly perfect however advising the box colliders were helpful.I managed to make it using one box collider as trigger per track. Thank and Cheers..

avatar image diddydale_95 · Feb 13, 2014 at 01:33 PM 0
Share

Sethuraj, how was you able to create the script? I plan to do the same with box colliders and as iamvishnusankar's answer was really helpful, I am still unable to get my head around the coding.

avatar image iamvishnusankar · Feb 13, 2014 at 01:38 PM 0
Share

@diddydale_95

Check this question. This might be helpful for you.

[ prefab generator in C# for endless runner[Solved]][1]

[1]: http://answers.unity3d.com/questions/637863/creating-a-random-prefab-generator-in-c-for-endles.html

Just call the CreatePrefab() (Check the above link to know what it is)function as soon as you enter/exit trigger :)

avatar image pKallv · Mar 03, 2014 at 05:28 AM 0
Share

I am jumping into this thread with a question, hope that is O$$anonymous$$. sethuraj is stating "moving the world around him", why is that and not moving the runner? Is it to save space in the world terrain?

avatar image whydoidoit pKallv · Mar 03, 2014 at 05:29 AM 0
Share

We'd prefer them as a new question with a reference or as a comment not as an "Answer" which means "Solution" on UA - I have converted it for you this time.

avatar image
0

Answer by Kiloblargh · Mar 03, 2014 at 05:49 AM

I am surprised you would see floating point precision errors in such a short distance.

If that's really going on, how about using a double?

Your real problem is probably caused by moving it by a factor of Time.deltaTime every frame, which is a lot more error-prone than moving it a fraction of a set distance relative to the elapsed time since the last reset.

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

22 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

Related Questions

How can I make my animation to cover a particular distance? 0 Answers

Infinite runner, insert customized text inside coins and obstacles 0 Answers

How to create a "save me" feature like subway surfers .temple run, etc ? 0 Answers

Object Pooling: deactivating vs. moving 1 Answer

I have a problem with the infinite runner tut by mike geig 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