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 Adecker246 · Mar 16, 2012 at 04:04 PM · androidiosplane

Dynamically Repeat plane to possible infinity

I am creating a 2D game and in order to create a good sense of movement I am using an image projected on a plane that acts as a backdrop. However, the game could go on for an infinite amount of time as it is a flying-side-scroller, thus I need the backdrop to repeat to infinity dynamically. Now obviously I cant just tell the computer to repeat it to infinity in the onStart() as this would crash everything, so I need to do it dynamically. This means I need to repeat it as the user nears the edge of the plane. I have several attempts but the plane always spawns in the wrong place and I can not figure it out. A skybox will not work as it does not create the sense of movement I need.

Read the comments, they explain quite a bit of stuff Thanks for reading. Hope it wasn't a book!

------------------------Code-------------------

 var planeWidth: int;
 var plane : Transform;
 var player : Transform;
 var middle : Transform;
 var right : Transform;
 function Update () {
 Debug.DrawRay(Vector3(player.position.x,player.position.y,player.position.z), Vector3(plane.position.x + (1500), plane.position.y,plane.position.z), Color.blue);
 //1500 is the plane width?? I dont know was a shot in the dark.
 
 if(Physics.Raycast(Vector3(player.position.x,player.position.y,player.position.z), Vector3(plane.position.x + (1500), plane.position.y,plane.position.z),100)){
 
 Debug.Log("Something in the way :)");
 
 //ray cast tells me if the plane is still there. Raycast at an angle so the user never sees the end of the plane and the new plane is there before the user hits that position.
 
     }else{
     //spawn the plane
     
     Debug.Log("Need to draw new backdrop");
 
         planeWidth = Vector3.Distance(middle.position, right.position);
         //get the width of the plane. two empties in the middle and right and get the distance between them, there is where the plane needs be spawned.
 
     Instantiate(plane, Vector3 (plane.position.x + planeWidth, plane.position.y, plane.position.z), Quaternion.identity);
 
     
             //should work unless I missed something stupid, or am way off track lol. Thanks guys!
     }
 }
Comment
Add comment · Show 7
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 ByteSheep · Mar 16, 2012 at 11:41 PM 0
Share

It looks like you have the right idea, what exactly is the problem? Is the new plane spawning at the wrong position and if so, is it slightly off on the x, y or z axis or is it spawning in the wrong area altogether? thanks

avatar image Adecker246 · Mar 17, 2012 at 03:10 PM 0
Share

Its spawning at a weird rotation and I cant figure out how to rotate it to be parallel to the plane....

avatar image ByteSheep · Mar 17, 2012 at 04:45 PM 1
Share

Is this script on the camera object? If it is then you could try replacing the line:

Instantiate(plane, Vector3 (plane.position.x + planeWidth, plane.position.y, plane.position.z), Quaternion.identity);

with:

Instantiate(plane, Vector3 (plane.position.x + planeWidth, plane.position.y, plane.position.z), plane.rotation);

I'm guessing that the plane variable in your script is set to the transform of the background.. Basically try replacing Quaternion.identity with the actual rotation of the background ;)

avatar image Adecker246 · Mar 18, 2012 at 03:36 AM 1
Share

well, I feel stupid! LOL. How did i miss that :) thank you so much! You should write that as an answer so i can accept it and you get credit where credit is due

avatar image ByteSheep · Mar 18, 2012 at 04:04 AM 0
Share

No problem, glad I could help ;D

Show more comments

1 Reply

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

Answer by ByteSheep · Mar 18, 2012 at 04:27 AM

Answer in the comments, haha thanks..

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 kranthi.G · Jun 24, 2013 at 10:19 AM 0
Share

Hi There,

$$anonymous$$ay i know how it works exactly?

Regards, $$anonymous$$ranthi

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Android/IOS First Person Shooter 2 Answers

Divide resolution and stretch to screen/window/canvas 1 Answer

Audio Clip won't play on iPad when loaded from Resources folder 0 Answers

Store/Stack Items 0 Answers

Unity 5 splash screen problem? (Android and iOS) 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