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 /
This question was closed May 15, 2017 at 11:02 AM by DerpyGamerYT for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DerpyGamerYT · May 15, 2017 at 05:19 AM · rotationobjectobjectsnot working

Can you make it where an object can't move along an axis without barriers? Even when acted on my a force?

I have an object, you can only move it along the X axis, but if you move it a lot, it will wobble and move along the Z axis. Here is a video to show what I mean.

https://youtu.be/CyrsZmt2dRg

I tried puting this code in the Update method and FixedUpdate method but no luck, I didn't get errors for the code though

 Vector3 Pos = rb.transform.position;
 Quaternion Rot = rb.transform.rotation;
 
 
 Pos.z = 0;
 Rot.y = 0;
 

and I tried without putting rb, with no luck. I tried putting the code in a while loop, and unity froze :P

I tried not to ask dumb questions, but I haven't found any solutions, this is my first time using unity and C#.

Comment
Add comment · Show 1
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 RobAnthem · May 15, 2017 at 07:52 AM 1
Share

Well that code would of almost worked, but the Quaternion rotation and Vector3 position are struct fields of the Transform, you can't edit them outright with a reference. Just re-assign them afterwards like this.

  Vector3 Pos = transform.position;
  Quaternion Rot = transform.rotation;
  
  
  Pos.z = 0;
  Rot.y = 0;
 
 transform.position = Pos;
 transform.rotation = Rot;
  

Or a shorter version.

 transform.position = new Vector3(transform.position.x, transform.position.y, 0);
 transform.rotation = new Quaternion(transform.rotation.x, transform.rotation.y, 0, transform.rotation.w);


Also keep in $$anonymous$$d this won't account for any $$anonymous$$or losses in speed due to friction changes, any subtle collisions that may of caused you to wobbled will still effect Velocity, but won't alter your position, and may not be noticeable.

2 Replies

  • Sort: 
avatar image
2
Best Answer

Answer by NoBrainer-David · May 15, 2017 at 09:46 AM

You can use the rigidbody component to constrain the objects position and rotation. See the image below.

You probably want to constrain the z-axis position and the x- and y- axis rotation.

alt text


rb-constraints.png (17.6 kB)
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 DerpyGamerYT · May 15, 2017 at 10:59 AM 0
Share

Yeah, I figured that out! But thank you anyway! I should have say that :P

avatar image
0

Answer by DerpyGamerYT · May 18, 2017 at 11:01 AM

Yeah, I figured that out! But thank you anyway! I should have say that :P

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I fix this randomly rotating gun to an unknown degrees? 1 Answer

Slowly Change One Object's Rotation To Match Another's 2 Answers

Objects not always Spawning At Correct Location 2 Answers

Why won't my thing rotate faster 2 Answers

Multiple Terrain objects good practice? 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