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
1
Question by Cameron 2 · Jun 05, 2010 at 08:35 PM · rotationgameobjectpositioncopy

Efficiently mimic movements of GameObject

I have a "Player" GameObject and then I have a script that creates a bunch (a lot) of GameObjects called PlayerSlave. Each PlayerSlave has this script attached:

var offset;

function Start() { var master = GameObject.Find("Player"); offset = master.transform.position - transform.position; }

function Update () { var master = GameObject.Find("Player"); transform.position = master.transform.position - offset; transform.rotation = master.transform.rotation; }

It sets the position to the master with the offset of how far it was from the master on initialization.

The player is a sphere and he is moved using left and right arrow keys, which apply torque.

Each slave consists only of the transform, the mesh, the renderer, and the script.

When I run it and there are a lot of PlayerSlaves, it gets pretty choppy. I'm wondering if there's anything I can do to fix that with how I'm achieving this effect. Is it because I'm setting the position and rotation instead of using like Translate, etc.?

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
4
Best Answer

Answer by DallonF · Jun 06, 2010 at 02:55 AM

May I ask why you're not simply parenting the "PlayerSlaves" to the master? If you do that, Unity will automatically move them along with the parent.

Comment
Add comment · 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 Cameron 2 · Jun 06, 2010 at 04:31 AM 0
Share

Wow. I guess I'm just not experienced enough to have known I could do that. Thanks a bunch.

avatar image Mike 3 · Jun 06, 2010 at 11:50 AM 1
Share
  • from me for the simple solution :D

avatar image
3
Best Answer

Answer by Mike 3 · Jun 05, 2010 at 08:46 PM

One thing you could try is to cache the results of the calls, and use Transform references

using GameObject.Find frequently will slow things down a lot there is also a minimal benefit from not using transform, but using a stored variable of it (though as i said, it's minimal, so feel free to remove it for readability)

var offset; private var master : Transform; private var myTransform : Transform;

function Start() { master = GameObject.Find("Player").transform; myTransform = transform; offset = master.position - myTransform.position; }

function Update () { myTransform.position = master.position - offset; myTransform.rotation = master.rotation; }

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 Cameron 2 · Jun 05, 2010 at 10:53 PM 0
Share

Superb. This helped a whole lot. Thank you.

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

No one has followed this question yet.

Related Questions

How can I defer the recalculation of child transforms whilst modifying the parent transform? 0 Answers

Position and rotation of a game object acting wired 0 Answers

Problem with Instantiate 2D object to right position C# 1 Answer

postion scale and rotation greyed out and not working 1 Answer

How to rotate/position the child object independently of the parent? 3 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