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 FuryFight3r · May 16, 2017 at 01:46 PM · vector3rotaterotate object

Setting a specific rotation to an object C#

Hi there guys, I have been struggling a lot with both vector3 Rotations and Quaternions, what i am trying to achieve is simply a 'Set Rotation' I dont want to add nor subtract to or from the current rotation, i have tried this with both Vector3s transform.Rotate, and Quaternions Euler, and Quaternions rotation, but have had no success.. i simply want an object to be set to a rotation once this method is called. how can that be achieved easily? This is my method i am trying to call, and the the 'can' objects rotation to 0, 85, -25

     public void pickupCan()
     {
         can.transform.parent = holder.transform;
         can.transform.localPosition = Zero;
         pickedCan = true;
         can.GetComponent<Rigidbody>().useGravity = false;
         can.GetComponent<Rigidbody>().isKinematic = true;
 
 //Here is the issue
         can.transform.Rotate(new Vector3(0, 85, -25));
         
     }
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 TreyH · May 16, 2017 at 02:20 PM 0
Share

You can just set the rotation itself. The Quaternion object has a function to convert Euler angles into Quaternions.

 can.transform.rotation = Quaternion.Euler(0, 30, 0);

1 Reply

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

Answer by NoBrainer-David · May 16, 2017 at 02:19 PM

transform.Rotate will add a rotation. To set the rotation, use

 transform.rotation = Quaternion.Euler(0, 85, -25);
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 FuryFight3r · May 16, 2017 at 04:18 PM 0
Share

Thank you this has helped somewhat, but now i at least understand what is going wrong, i would like the object I'm trying to rotate, to face a certain direction after being parented to my character, but what i can see is happening is, this rotation is setting by world rotation, not its parents rotation, how can i over come this? i have made a video demonstration of what happens to better instruct of what i am trying to achieve.

In the video i have demonstrated that the object does not rotate to the parents rotation in the hierarchy rather it rotates still to the world's rotation.

At the start of the video i am showing pressing 'F' to call this piece of code transform.rotation = Quaternion.Euler(0, 85, -25);

Video Link HERE https://youtu.be/$$anonymous$$PjqB5RVTsA

In other words i want 'F' and on pickup to have the nozzle of the water can to face outward from the player with the rotation of 0 x 85 x -25

avatar image NoBrainer-David FuryFight3r · May 16, 2017 at 05:57 PM 0
Share

You can chain the rotations with the * operator. If you have a reference to your player, try:

 can.transform.rotation = player.transform.rotation * Quaternion.Euler(0,85,-25);

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

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

Related Questions

Rotate a gameobject using 2 fingers (Twist) 0 Answers

how to reorient the axes ? 1 Answer

How to rotate object from center of the object? 1 Answer

Rotating a character's velocity? 3 Answers

How do I make an object orbit another 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