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 Keavon · Jan 05, 2011 at 12:09 AM · movement3ddisablez-axis

All gameObjects with specific tag disable z axis as to not fall forward or backward?

Hello. I need to make it so multiple game objects do not fall forward or backwards, as to kind of act like a 2d game. An alternative to the tag would be to have the script on each gameObject. This method would actually be preferred. Thank you! -Keavon

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

Answer by Peter G · Jan 05, 2011 at 12:44 AM

You could manually go through and add components to all the objects that you want. If you wanted a script to do it at runtime, you could do something like this which will add them automatically for you:

//SceneManager.js //This goes somewhere in your scene. function Awake () { var specialObjs : GameObject[] = GameObject.FindGameObjectsWithTag("SomeTag");

  for(var obj : GameObject in specialObjs) {
       var comp : KeepOnZ = obj.AddComponent(KeepOnZ);
       comp.Init();
       //You could probably let Start() call itself in your other script.
  }

}


//KeepOnZ.js var zDepth : float;

function Init () { zDepth = transform.position.z; //Initialize your script. }

function Update () { transform.position.z = zDepth; //if you are going to be locked on the z-axis, then you can do: //transform.position.z = 0.0;

  //Or you could add some joints to lock its position as well.
  //Probably a Configurable joint.

  transform.eulerAngles.z = 0;
  //Don't let it rock side to side.

}

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 Keavon · Jan 05, 2011 at 01:15 AM 0
Share

Wow! Thank you so much! I just used the lower script and it worked great (I removed the comments). I didn't actually need to add it to every one at the beginning, as I just added it to the prefab and it worked like a charm! Best answer. Thank you! $$anonymous$$y game is really progressing!

avatar image
1

Answer by Justin Warner · Jan 05, 2011 at 12:36 AM

Try (Didn't test):

var yAxis;

function Awake () { yAxis = transform.position.y; } function Update () { transform.position.y = yAxis; }

That MIGHT work.

Comment
Add comment · Show 3 · 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 Keavon · Jan 05, 2011 at 01:13 AM 0
Share

Thank you. I did ask for a z axis, but that isn't hard to change. I actually used the script from Peter G, though I think yours would have worked too. You might have been missing the "transform.eulerAngles.z = 0;" thing, but I don't now what that does. I shall vote up your answer for your effort (does that increase your reputation score?).

avatar image Peter G · Jan 05, 2011 at 02:13 AM 0
Share

@$$anonymous$$eavon, the eulerAngles thing just makes sure that your objects won't swing off the xy plane. $$anonymous$$ost of the time your won't need it, it just makes sure in those special cases.

avatar image Justin Warner · Jan 05, 2011 at 02:39 AM 0
Share

Yes, it does, and 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 the player position updates randomly when the player isn't movingl? 0 Answers

Unity not recognizing true statement. 1 Answer

basically i am having collider issues and idk wat to do 1 Answer

Vertical 3-way/lane movement? 0 Answers

active ragdoll rotation is not working 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