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
-1
Question by Zitoox · Oct 24, 2016 at 08:09 PM · scriptingbasicsrotate object

How to make the character rotate

I am trying to make an AirPlane in my game. I have a script that make it move forward ALL the time, which makes the game more realistic. BUT i wanted to also rotate the plane with A and D to Left and Right. The problem is that i don't know how to make this... How do i rotate an object with rigidbody to left and right in script?

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

Answer by Glurth · Oct 24, 2016 at 08:30 PM

You want to use the object's transform.localRotation (https://docs.unity3d.com/ScriptReference/Transform-localRotation.html)

You an assign an left/right angle as a rotation around the Y-axis like so: gameObject.tranform.localRotataion= Quaternion.Eulers(0,angle,0); (https://docs.unity3d.com/ScriptReference/Quaternion.html)

A positive angle will rotate it one direction, a negative angle will rotate it the other direction.

Note: as you rotate the plane, it's FORWARD direction of motion should probably change too! If so, make sure to use the transform's forward direction for your motion: gameObject.transform.forward defines the direction the transform is facing. (https://docs.unity3d.com/ScriptReference/Transform-forward.html)

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 Robak · Oct 24, 2016 at 10:03 PM

https://docs.unity3d.com/ScriptReference/Transform.Rotate.html

I know somthing only about 2d. There is 2 way to do it. airplane.transform.rotation(vector 3) and airplane.transform.rotate(x,y,z) in first object move all the time by vector 3 given in parameter function second one rotete 1 time airplane to parameters in function

Next time give more information. Is your game 2d or 3d etc.

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 Zitoox · Oct 25, 2016 at 01:57 AM -1
Share

Are you sure you read my question? Clearly not.

Why do i have to say if my game is 2D or 3D if i already said "it moves forward and i want to know how to move it sideways". You can't do this in 2d.

Also, the link doesn't match. That doc is referencing how to move a gameobject from time to time ins$$anonymous$$d of using inputs like A and D.

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

60 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

Related Questions

How can I slowly rotate a sprite to face its movement direction? 1 Answer

How can I introduce a turning function for my player in this script? 1 Answer

how to make a detect rotation script for negative rotation too 2 Answers

Object modified in script not modified in scene 0 Answers

How i get my cloud position in other script? I want to use this temp value in other script. 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