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 presidentgod123 · Dec 28, 2019 at 10:30 PM · relative rotation

How do i rotate an object relative to itself?

I started making a racing drone sim in Unity and ive already established things like physiks using rigidbody (gravity, relative thrust, collision) and attached the camera to the drone. I thought i had the controlls working but when the camera was attached i noticed that the rotation happend relative to the world and not the drone (i used this when "w" was pressed: transform.Rotate(transform.forward); i dont know why that doesnt work because i was able to get relative thrust with: rb = rigidbody, rb.AddForce(transform.up*thrust);) i tried getting the current rotation of the object and setting that as the default so that the following rotations would be happening relative to that using vector3 and quaternion. but since im pretty new to unity i dont really know how to do that. Maby im just thinking too complicated.

So to summerize: id like the object to rotate for example to the right relative to itself but i dont know how.

thanks for any help!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by LOSTSOUL86 · Dec 29, 2019 at 10:21 AM

@presidentgod123

if you assign "Rotation" value it is always set to the global coordinates. To rotate object certain value from its current orientation use Rotate method. For example:

 rotationAngle = 5; //degrees from the current orientation
   camera.transform.Rotate(Vector3.forward * rotationAngle);

This means whatever object orientation is at the moment -> rotate game object 5 degrees right from this orientation.

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

Answer by xibanya · Dec 29, 2019 at 06:43 AM

It sounds like you'd like to use localRotation (accessed via transform.localRotation.) I could probably use more details about your specific case, but your object is already rotated in the "forward" direction. Multiplying a quaternion is effectively like adding, so you could keep the transform's original local rotation stored in a variable like private Quaternion startRotation; and keep a private float horizontal; In this example, you'd also have a public float turnSpeed; in the inspector.

on update do something like

 horizontal += Input.GetAxisRaw("Horizontal");
 Quaternion targetRotation = startRotation * Quaternion.AngleAxis(horizontal, Vector3.up);
 transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation, turnSpeed * Time.deltaTime);
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
avatar image
0

Answer by presidentgod123 · Dec 29, 2019 at 04:43 PM

thanks for the replys but i found a solution while looking at someone elses question here: http://answers.unity.com/answers/1160252/view.html But as a newbee i still learned a lot from your answers. thank you

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

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

118 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 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

Quaternions, relative clamped rotation, look rotations in spaceship movement 0 Answers

Rotate object around certain point using phyics 0 Answers

Parent rotation on a BoxCollider2d 0 Answers

Set a rotation relative to position between two objects. 0 Answers

really annoying rotation problem. 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