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 kaiserkappel · Dec 13, 2012 at 05:29 PM · javascriptinstantiateontriggerenterdelay

Instatiate inside OnTriggerEnter gives unwanted delay

Hello Everyone! I'm trying to create a scrolling street. Each time the street hits a box collider, more of the street (a new "street segment" if you will) is generated off screen so that it appears endless. My problem is that when I generate the next street segment there is a variable delay, creating openings between segments. This is especially apparent when I boost the speed at which the segments scroll. Here is my code currently; it is attached to an empty game object with a box collider called "StreetCollider":

 #pragma strict
 
 //Detects when a street hits the collider, creates and deletes streets
     
 var nextStreet : GameObject; //Pass it the next street to create
                              //Next step is to create randomstreet generator script and pass return
                              //value to this variable. Make this variable private.
     
 function OnTriggerEnter (currentStreet : Collider) {
     
     //Get some data from the current street
     
     //This helps to get the size of the currentStreet object's mesh
     var mf : MeshFilter = currentStreet.GetComponent(MeshFilter) as MeshFilter;
     var mesh = mf.sharedMesh;
     
     //Gets the mesh size and scale
     var size = mesh.bounds.size;
     var scale = currentStreet.transform.localScale;
     
     //Create a clone of what's passed to nextStreet
     if(Instantiate(nextStreet, Vector3(0, 0, -size.y*scale.y), currentStreet.transform.rotation))
         Debug.Log("Street collider collided with!");
         
 }
 
 function OnTriggerExit (currentStreet : Collider) {
     //Destroy the currentStreet when it exits the trigger
     Destroy(currentStreet.gameObject);
 }

I'm a programmer but I'm relatively new to the concepts of scripting versus more programmatic coding, so I'm a bit hazy on encapsulation methods and message passing in Javascript. Would calling a different function outside of OnTriggerEnter help? Would creating some of the data outside of OnTriggerEnter help and if so, where would I put the data? Could a possible fix include the FixedUpdate function?

Thank you for reading this and any help is greatly appreciated!

Comment
Add comment · Show 3
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 bompi88 · Dec 14, 2012 at 12:18 AM 0
Share

It's kind of unclear what you mean by delay. Are you referring to time delay or position offset?

avatar image kaiserkappel · Dec 14, 2012 at 06:28 PM 0
Share

Sorry, I meant position offset. I've scrapped the idea altogether to scroll the street and ins$$anonymous$$d opted to have the player progress the street's generation. I'm hoping this will cut out the lag.

avatar image bompi88 · Dec 14, 2012 at 07:37 PM 0
Share

Let me know if it won't ;-) And if it does work out, please post an answer to your question and mark it as accepted.

1 Reply

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

Answer by kaiserkappel · Dec 17, 2012 at 03:21 PM

I've since decided to move the character and other NPCs on top of the static generated street segments. This is working a lot better so far.

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

Need help understanding scripted prefab behavior - when I click one, the script runs on ALL prefab instances, not just the one I clicked. 3 Answers

How to Select between two prefabs randomly ? 1 Answer

Simple Instantiate gameObject problem 3 Answers

Instantiate object in for loop with array 2 Answers

Instantiate without (clone) in JS. 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