• 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 harveyhb · Dec 13, 2013 at 12:11 PM · positiontransform.position

Player position with Joystick and Head Tracker

This is what I am trying to achieve. The player will move in the x,y,z direction using a joystick, I have this working already. Now I am trying to add head tracking, i.e the camera moves using a tracker on the players head. I have the position values coming in from the tracker fine. I want both the joystick and the head tracking to be working together.

However, what I am struggling with is combining the joystick input and the tracker input. Here is my script so far.

 Vector3 move = Vector3.zero;
 move.x = (leftController.JoystickX * xmovScale);
 move.y = (rightController.JoystickY * ymovScale);
 move.z = (leftController.JoystickY * zmovScale);
 fpc.transform.Translate(move);
 
 fpc.transform.position = new Vector3 ((rightController.Position.x) * headMoveScale, (rightController.Position.y) * headMoveScale, (rightController.Position.z) * headMoveScale);
         

Comment
Add comment · Show 6
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 harveyhb · Dec 13, 2013 at 11:00 AM 0
Share

and I apologise for the formatting, I can't get it correct.

avatar image KellyThomas · Dec 13, 2013 at 12:53 PM 0
Share

You set the camera rotation by by accessing "`fpc.transform.rotation`". The real question is what is the nature of the input from the head tracker, and what kind of behavior do you want the camera to have?

avatar image Bunny83 · Dec 13, 2013 at 01:06 PM 0
Share

@harveyhb:
HowToFormatCode

avatar image Bunny83 · Dec 13, 2013 at 01:30 PM 0
Share

@$$anonymous$$elly$$anonymous$$:
HeadTracking is usually more about offsetting the camera.
See this HeadTracking-video

However to get an effect like in this video you have to heavily adjust the projection matrix to get a view like this. However the basic principle stays the same. The headtracking system deter$$anonymous$$es your heads position in front of your screen so you can adjust the camera position in relation to your head.

If you really want to do what you've seen in the video you only have to work with the projection matrix. Usually your camera position is your virtual camera position which is at the players position and the near-clipping plane has a fix distance from the camera position and you have a certain fov.

With headtracking you have a fix near-clipping plane (at the players position) and using the tracking information to calculate the projection parameters to represent the cam position (your head). That's not so easy if you don't know how perspective projection works ;)

Ps: If you really want to do something like that, there are some threads around the net (use your google-fu).

avatar image KellyThomas · Dec 13, 2013 at 01:49 PM 0
Share

Very good video, I imagining taking the heads rotation relative to a deadzone and using that to rotate the camera, i.e. player looks to the side of the screen and the camera turns to face that way. The effect in the video would be much more challenging to implement.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Dec 13, 2013 at 01:14 PM

From your description and your code it's not really clear what you actually want to do. In your last line you set the position to an absolute value. You do this every frame so you can't add a relative motion to it since you reset it each frame.

I guess that you want the headtracking position as offset to your actual character position.

Since headtracking usually just affects the camera and not the player you could simply apply the tracking position to the localPosition of the camera only. So the camera still moves along with the player but gets an offset from the headtracking. Depending in which space you get your tracking information (probably in camera local space) you might have to transform the position into "local player space". However that soley dependy on what kind of game you actually have (fps, tps, 2.5d sidescroller, ...)

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.

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

18 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

Related Questions

collider triggers transform position 1 Answer

How to find total distance from start to end of an array which stores positions in vector3? 2 Answers

Setting transform.position not behaving properly 2 Answers

I can't change my players position manually 0 Answers

How can I move an object to a (0,0) and scale it to (0,0) at the same time? 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