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 Dan.R · Jan 07, 2013 at 11:47 PM · instantiatetransformpositionupdateroad

Instantiating road pieces without any spacings between

Hello!I`m tring to build an infinite road out of different pieces,each road piece moves on the z axis.Basically i want to instantiate a new piece when the prevoius one has reached a certain position in z axis without any spaces between them . I have tried alot of methods but none seems to work right .Mainly i noticed that the update function reads the position a bit late since the road piece moves more space units per frame, and the faster the road moves the more inaccurate it's transform.position.z is read.I really need some help on this since i've been struggling for days to solve it with no luck.

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 Vonni · Jan 08, 2013 at 09:41 AM

Assuming you have a lot of different roads:

You should create a joint (empty gameObject) on the end of the road that you can use to snap to. And then have the pivot of every road prefab at the other end.

And then in the script you should Instantiate it, parent it and then move it to the joint. Maybe have one master controller that controls the speed of the road and parent everything to that.

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
avatar image
0

Answer by Dan.R · Jan 08, 2013 at 12:37 PM

Thanks Vonni ! I didnt know about jointHinges this works great.So basically i added an empty with rigidbody and a box collider with the length of the road piece, I positioned it under the road so it doesnt collide with other objects on the road,added the road piece as a child of the empty,set the speed of the initial piece to 50 and the next instantiated one to 70 so it outruns and then snaps to the first piece and then on collision enter changed its speed to 50 again to slow it down for the next instantiate. This is the script i used:

 var roadSpeed :  float = 70;
 
 function Update () 
 {
 
   transform.Translate(0, 0,roadSpeed*Time.deltaTime);
 
 
 if (gameObject.transform.position.z >=200)
 {
       Destroy(gameObject);
 }
 }
 
 function OnCollisionEnter(c : Collision) {
 
     var joint = gameObject.AddComponent(FixedJoint);
     joint.connectedBody = c.rigidbody;
     roadSpeed=50;
 }
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 Vonni · Jan 08, 2013 at 09:31 PM 0
Share

This was not what I meant, but glad you found a way :) Why are you using rigidbodies?

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to follow multiple clones positions of an instantiate prefab having a velocity ? 1 Answer

How can I get a GameObject's transform in game and set that to a variable? 1 Answer

Vector3.Lerp works outside of Update() 3 Answers

Use GameObject's global position instead of local position 3 Answers

How do I get the opposite position of an object that spins around another object... 0 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