• 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 avillago · Mar 04, 2012 at 06:07 AM · kinectforwardflight

Kinect controlled flight issue

Hello, I'm creating a game that uses Kinect to control flight, but I am having really big problems. The speed is constant, and the camera is attached to the head joint, so the idea is wherever the player turns the head, is where the player should turn and look at and continue moving forward. Right now instead of turning, the character it's only changing the forward vector's direction, and it's making my character fly sideways or even backwards. Any ideas on how can I achieve that???? Here's my code:

  Vector3 newDirection = Vector3.zero;
  newDirection = new Vector3(GameObject.Find("MainCamera").transform.forward.x, 0, GameObject.Find("MainCamera").transform.forward.z);
  if (newDirection != Vector3.zero)
  {
       transform.rotation = Quaternion.LookRotation(newDirection);
       transform.forward = newDirection;
  }

  transform.Translate(transform.forward * (movementSpeed / 2) * Time.deltaTime);

Any help is appreciated

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Mar 04, 2012 at 06:10 AM

The problem here is the Translate direction: Translate by default uses local coordinates, thus you can simply use Vector3.forward to make it go in its forward direction.
But you could do the whole job in a much simpler way: get the main camera's forward direction in newDirection, zero the y component and assign it directly to the character's transform.forward vector: this will rotate the character to the main camera's forward direction - but only in the horizontal plane:

    Vector3 newDirection = Camera.main.transform.forward;
    newDirection.y = 0; // force direction to the horizontal plane only
    transform.forward = newDirection; // turn the character to newDirection
    // move in the character's local forward direction:
    transform.Translate(Vector3.forward * (movementSpeed / 2) * Time.deltaTime);
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 avillago · Mar 04, 2012 at 06:18 AM 0
Share

It worked!!! Thanks a lot!!!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our 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

Detect player blinking in real time w/ kinect or webcam? 1 Answer

How to skin a realtime rig (created by Kinect v2) ? 0 Answers

Kinect Joint Position Jitters on one machine but not another. 0 Answers

Zigfu obsolete code? 1 Answer

Possible fix for weird bending in kinect model 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