Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 xToxicInferno · Feb 13, 2010 at 07:39 PM · 2daxislock

How do i lock out a axis

I am making game that is a top down 2-d game. I only want things to move in x and z, keeping anything from going to y. The problem is, i have the AI set on a waypoint system that uses rigidbodies, and some times when either myself, or other enemies collide with a enemy, it knocks them up or down in the y axis, making them impossible to shoot and kill yet they can still hit me, as they are scripted to aim in all 3 axis which is fine as it is universal and looks cool.

So the bottom line is, how can i lock the objects in x and z and out of y. My thought was to have it keep resting it's y axis every frame in the update function, but i have no clue how to do that, and i fear it would either look jumpy, or make it lag a lot.

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

1 Reply

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

Answer by Ashkan_gc · Feb 13, 2010 at 08:18 PM

the best way is to use a configurable joint and lock the motion in y axis. you can do something like this in update with

transform.position.y=0;

but using joints is the correct way.

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 xToxicInferno · Feb 13, 2010 at 08:26 PM 0
Share

Well i tried the joint, and all that does is make it so when i run into a enemy they fly up into the air, then back down to their usual height. I also locked Y motion and angular y motion.

avatar image Cyclops · Jun 27, 2010 at 06:28 PM 1
Share

@Ashkan, one $$anonymous$$or point - that's Javascript. In C# you can't assign to Y, you have to do: transform.position = new Vector3(x, 0, z)

avatar image Ashkan_gc · Jun 28, 2010 at 03:09 AM 0
Share

yes! in C# structs are paased by value so the reference of a vector3 will not be paased and you should get it's reference if you want to set it that way

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 do I lock Y Axis movement for Parented Camera? 3 Answers

Camera moving in one direction? 2 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

2D, lock the "y" axis 1 Answer

2D Player Movement 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