• 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
Question by Matt-KP · Apr 18, 2012 at 10:39 AM · javascriptgui

Move and Repeat Terrain

I have set up a Terrain in the editor with a main camera pointing down the Terrain from the start of it.

I need some how for the Terrain to move towards the camera slowly, but the problem I am facing is to get the Terrain to repat so it looks like it is never ending.

So once the Terrain starts to move towards the camera the same Terrain will have to be created and joined to the end of the first so they keep moving towards the camera seemlesley.

The best way I can think to describe it is kind of like a Tredmill.

Comment
BiG

People who like this

1 Show 0
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

Answer by Kryptos · Apr 18, 2012 at 12:32 PM

You can duplicate the terrain then disconnect the terrain when one goes out of view and move this same terrain down (also out of view) and reconnect.

Comment
Matt-KP
BiG

People who like this

2 Show 2 · 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 Matt-KP · Apr 18, 2012 at 01:01 PM 0
Share

@NicolasMusset That sounds like exactly what I need, is there a chance you can start me off with this, kind of a noob with Unity still :)

avatar image Kryptos · Apr 25, 2012 at 02:44 PM 0
Share

I know that my answer is too short. It is just an idea. Unfortunately I don't have the time to write a proper answer. I hope somebody will help you do that.

avatar image

Answer by T27M · Apr 18, 2012 at 02:44 PM

Create a prefab with the terrain in it and a rigidbody attached. Remove gravity. Create a cube and set it to a trigger. (1,1,1) Scale is fine.

Position your camera, You will have to tweak this so you don't see the ground plane spawning.

Move the cube behind your camera. Make sure the cube is level with the ground plane so in my tests both were Y = 0. Mine is at 256,0,-245.

Create an empty object. I placed mine at 0,0,0 my terrain was set to 512 by 512 so I put my camera at 256,5,0. Half way between the terrain.

Create a javascript and attach it to the cube you created and enter this code.

  // Terrain Prefab
  var terrain : GameObject;
  //Spawn Point
  var spawn : GameObject;
  //Speed at which the ground mvoes
  var power : float = 1000;
 
 // calls the spawnTerrain function and spawns a terrain when the game starts
 function Start () {
     
     spawnTerrain();
     
 }
 
 //Crates the terrain from the prefab and applies movement.
 function spawnTerrain ()
 {
     var spawn = Instantiate(terrain, spawn.transform.position, spawn.transform.rotation);
     spawn.rigidbody.AddForce(Vector3(0,0,-power));
 }
 
 // when the terrain collides with the cube a new one is spawned and the current one is destroyed
 function OnTriggerEnter (other : Collider)
 {
     Debug.Log("Spawn");
     Destroy(other.gameObject,2);
     spawnTerrain();
     
 }
 


Comment
Matt-KP

People who like this

1 Show 4 · 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 Kryptos · Apr 18, 2012 at 04:15 PM 1
Share

Interesting idea. But instantiating terrain can be quite expensive. You better instantiate two terrains at the beginning and recycle them.

avatar image T27M · Apr 18, 2012 at 04:55 PM 0
Share

Hmm yeah youre right, It shouldn't be hard to modify todo that.

avatar image Matt-KP · Apr 25, 2012 at 02:28 PM 0
Share

Thanks for the help so far, home can I modify the code to be like @Kryptos answer

avatar image TheProfessor · Jun 10, 2015 at 11:50 PM 0
Share

I think you need to make the terrain not-static, does this have problems?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Setting Scroll View Width GUILayout 1 Answer

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

FPS keep a loadout 0 Answers

Aspect ratio keeping guitexture scaling 1 Answer

GUI Textures and Colliders 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