Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 husbandofemily · Oct 18, 2013 at 10:56 AM · terrainarrayposition

Move all objects in scene (including terrain)

Hi all.

I'm trying to create a function that, when called, creates an array of all objects in the scene, iterates through it, and moves everything to another point (keeping relative positions). I'm almost there, using the code below; it creates a game empty, works out the iteration's position relative to it, and applies that difference to world 0,0,0. This works for all GameObjects:

var gameObjs : GameObject[] = FindObjectsOfType(GameObject) as GameObject[];

var newEmptyGameObject : GameObject = new GameObject("master");

newEmptyGameObject.transform.position = gameObject.transform.position;

for(var thing : GameObject in gameObjs) { var tempV3 = thing.transform.position + newEmptyGameObject.transform.position; thing.transform.position = Vector3(0,0,0) + tempV3; print(thing.name); }

(please excuse the lack of formatting, I'm doing this on an old browser at work...)

My problem is, the terrain doesn't get included in the array, and so isn't moved along with just about everything else. I think particles are also left. I'm guessing the terrain isn't a GameObject, but an Object?

I've tried changing the "GameObject" parts to "Object", but then I can't access the transforms and move everything.

I'm pulling my hair out, can anybody point me in the right direction please?

(p.s I know this is expensive to do; I've omitted an if() statement from the for(thing) part, so only root items are moved).

Cheers

Ian

Comment
Add comment · Show 2
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 tanoshimi · Oct 18, 2013 at 10:59 AM 0
Share

Ummmm.... Why do you want to move everything?!

avatar image husbandofemily · Oct 18, 2013 at 11:01 AM 0
Share

To stop floating point error. I want to periodically move everyting so the player is approximately at 0,0,0.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by fafase · Oct 18, 2013 at 11:11 AM

Wrap everything into one empty game object except your player.

You can then move that game object around and all will follow (except your player).

Following is irrelevant to the question:

Note that if you need to do so because your player gets too far and you reach floating point inaccuracy (the warning), you may have a level design issue.

That means your level is about 10km long, you may want to cut that into smaller parts (personal point of view).

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 husbandofemily · Oct 18, 2013 at 11:27 AM 0
Share

Fafase- that was the first thing I tried, but I was still struggling to find none gameobjects. As for the level design, it's an open world design, hence the problems. I'll have to break it down into smaller chunks and have loading screens, I suppose. Thanks for your help

Ian

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

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

Related Questions

How to store previous locations in a list to teleport? 2 Answers

problem moving a prefab object in script (c#) 0 Answers

Transform Checking on all Array Objects (JS) 3 Answers

Position an array of objects randomly 1 Answer

how to move hinge joint anchor with the object? 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