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 potryvayev · Mar 12, 2013 at 11:48 AM · javascriptprefabspoolingplacement

Need to fix a small gap between two objects, which created by code

Hi, guys!

I'm working on endless runner game. I'm creating the prototype now. Game world created from some prefabs (ground parts), which were preloaded from an array. Some kind of pooling system. Whole game world creates from 3 ground parts/blocks, which sticks and moves together. All these first blocks/prefabs placed by code in one JS file, which attached to an Empty Game Object (some kind of World Inspector). Those tree blocks stick perfectly without any gaps (visible seams) between them.

alt text

When first block moves out of the screen I deactivate it and place the new one at the end of the stack. Check for deactivating the object happens in other JS file, which is connected to a prefab/block itself. And here the problem appears. Every new blocks I've created have a small seam/gap between him and others blocks.

alt text

Here you are some check code sample:

  // If object is out of screen, than...
     if ( transform.position.z <= -30 ) {
             
     GameObject.Find("Pool Inspector").GetComponent(objectsPoolingScript).PrefabPlacement(false); // Execute the function for new prefab activation
     gameObject.SetActive (false); // Deactivate the prefab, which is out of screen
     transform.position.z = 0.0; // and reset its position

When I've checked Z position of the object I saw that my check executes not in perfect -30.0 value, but something around -30.045 value. Those value changes time to time. So, I think that this .045 is a gap problem. But I can't understood how to fix it and why is it happen? Maybe there's a delay between send some values from one script to another? But how to fix it?

So, maybe you, guys, will able to help me to settle it? Thanks.

seam_bug_01.jpg (128.0 kB)
seam_bug_02.jpg (186.7 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 robertbu · Mar 12, 2013 at 12:21 PM

You did not show much of your code, so I'm left to guess a bit. The overlap of -30 will occur if you use Time.deltaTime to scale your movements. Or if you are using some fixed scale, it will occur when the movement rate does not evenly divide into -30. There was an almost identical questions asked just a few hours ago:

http://answers.unity3d.com/questions/415231/moving-gameobject-and-reseting-issues.html

A fix is to compensate for the overlap. So in your case, you might set

 transform.position.z = transform.position.z + 30;

Another fix might be to select a speed that evenly divides into length, and use FixedUpdate().

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 potryvayev · Mar 12, 2013 at 01:40 PM 0
Share

Thanks for your answer and for the link. I've settled the problem by mix of yours and other guys comments from the similar answer. I've just find out those $$anonymous$$TA I have and include it in new object placement. Like this:

 if ( transform.position.z <= -30.0 ) {
         movingDelta = transform.position.z + 30.0; // Find out current delta        
         GameObject.Find("Pool Inspector").GetComponent(objectsPoolingScript).PrefabPlacement(false, movingDelta); // after that we activate function for new prefab generation
         gameObject.SetActive (false); // deactivate the prefab
         transform.position.z = 0.0; // and reset its position
         
     }

And after that when I place the new prefab I use:

 prefabsPool[randomPrefab].transform.position.z = 60.0 + delta; // move new prefab into right position including small delta we have

That works fine. So, thank you for moving me from that STOP point. :)

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

11 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

Related Questions

Assets/Scripts/Cubemove.js(44,167): BCE0017: The best overload for the method 'UnityEngine.Mathf.Round(float)' is not compatible with the argument list '(boolean)'. 1 Answer

Convert GameObject in CarControl 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

pool lists and instantiating... 0 Answers

Procedural platformer: add/remove or pooling for platforms? 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