Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 rsud · Jan 21, 2013 at 01:04 AM · controllerrollpitchyaw

pitch yaw roll user input on an object?

How would I implement (in c#) a pitch yaw roll input controller on a flying gameobject?

I'm looking at past posts but not getting a clear idea.

I want the user to input from a keyboard

  - a or d for positive/negative yaw

  - w or s for positive/negative pitch

  - q or e for positive/negative roll


The control should work as if sitting in the cockpit of the game object.

Does Unity offer a script to do this?

If not, could someone provide c# code to do this? I know how to get the user input. Need the code that applies the change to the gameobjects orientation.

     if (Input.GetKey(KeyCode.A))  "what goes here?" ;  //yaw left
     if (Input.GetKey(KeyCode.D))  "what goes here?"  ; //yaw right
     if (Input.GetKey(KeyCode.W))   "what goes here?" ;  //pitch up
     if (Input.GetKey(KeyCode.S))   "what goes here?" ; //pitch down
     if (Input.GetKey(KeyCode.Q))   "what goes here?" ;  //roll counterclockwise
     if (Input.GetKey(KeyCode.E))   "what goes here?" ; //roll clockwise

Appreciate any help as 3d geometry is not my strong suite. Thanks!

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 AlucardJay · Jan 21, 2013 at 02:46 AM 0
Share

http://keithmaggio.wordpress.com/2011/07/01/unity-3d-code-snippet-flight-script/

2 Replies

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

Answer by rsud · Jan 31, 2013 at 04:57 AM

http://keithmaggio.wordpress.com/2011/07/01/unity-3d-code-snippet-flight-script/

This link provided by alucardj above has some simple code that works great!

Thanks alucardj !!

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
1

Answer by robertbu · Jan 21, 2013 at 02:49 AM

In the couple of instances I've had to deal with kind of problem, my solution was to construct a gimble out of game objects. Note I was not using the physics engine, so I don't know how well this solution will translate to your flying object.

Create three empty game object and place then at the origin along with your flying object. By draggin and dropping in the hierarchy view, make all three children of each other. I don't think order matters, but when you get done you should have something like Yaw at the top, Pitch as the child of Yaw, Roll as a child of Pitch, and your flying object as the child of Roll. Next attached the following, short script to the Pitch, Yaw, and Roll game objects.

 using UnityEngine;
 using System.Collections;
 
 public class RotateByKey : MonoBehaviour {
     public KeyCode kcNegative = KeyCode.A;
     public KeyCode kcPositive = KeyCode.D;
     public Vector3 v3Rotation = new Vector3(0.0f, 1.0f, 0.0f);
 
     void Update () {
         if (Input.GetKey(kcPositive))
             transform.Rotate (v3Rotation);
         if (Input.GetKey (kcNegative))
             transform.Rotate (-v3Rotation);
     }

}

In the inspector, set the values for kcNegative (the keycode for negative rotation), kcPositive (the keycode for positive rotation), and v3Rotation (how the game object should rotate). Each empty game object should rotate about only one axis. So Yaw get (0,1,0), Pitch gets (1,0,0) and Roll gets (0,0,1). Note a larger value such as (3,0,0) will make the turn faster on the specified axis.

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 ZiggZagg37 · Sep 11, 2015 at 05:20 PM 0
Share

This was exactly what I was looking for and this approach helped me to get a gimbal model working correctly. Even though your answer was not voted the "Best" answer for this particular question, it was for me! -many thanks for posting this Robert.

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

12 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

Related Questions

How do I move this gameObject in 3 dimensions relative to itself? 0 Answers

How to get a rigidbody's Local Angular Velocity (Yaw, Pitch & Roll) ? 1 Answer

Setting the roll of a rotation 1 Answer

Convert directions in Vector3 to yaw/pitch/(roll),Converting directions in Vector3d to yaw/pitch/(roll) 0 Answers

Adjust Yaw For A Gliding (Like Superman 64) 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