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 /
  • Help Room /
avatar image
0
Question by Edwardayy · Jul 10, 2016 at 02:59 AM · c#playercontrollergoogle

[Daydream][C#]How would I make a simple directional controller with Google Daydream Controller?

I'm creating a game that uses the Daydream controller as a lightsource (via the gyro) and using the touchpad of the controller as a 4-way direction pad or scroller. I'm thinking of something similar to the Adventure Daydream sample but not exactly the same.

Upon looking at the Controller API basics I think I'll need to create a controller script that uses GvrController.IsTouching to track the position of the users finger on the touchpad, so if the users finger is on the top area of the touchpad then the player will move forward and so on...

 // Example: check the position of the user's finger on the touchpad
   if (GvrController.IsTouching) {
     Vector2 touchPos = GvrController.TouchPos;
     // Do something.
   }

Will this idea work? Would it be simple to create button parameters on the Daydream touchpad (ei if the finger is in position y=top and x=0 then player is touching button "forward")?

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 jdk1-0 · Jul 29, 2016 at 03:46 PM 0
Share

Here is some sample prototype code that I used:

 if ( GvrController.IsTouching )
 {
     // normalize -1.0 to +1.0
     var moveVector = 2 * GvrController.TouchPos - Vector2.one;
     // reverse y-axis (so up is positive). note: change -0.5f to -1.0f for full speed backwards
     moveVector.y = $$anonymous$$athf.Clamp(-moveVector.y, -0.5f, 1.0f);
     // we will multiply the magnitude and direction later
     var magnitude = moveVector.magnitude;
 
     // deadZone is a float value that allows ignoring the center of the touchpad*
     if ( magnitude < deadZone )
         moveVector = Vector2.zero;
         
     var direction = moveVector.normalized;
    
     // renormalize (without the deadzone) from -1 to +1
     magnitude = (magnitude - deadZone) / (1.0f - deadZone);
 
     // maxPlayerSpeed is another float
     moveVector = direction * magnitude * Time.deltaTime * maxPlayerSpeed;
 
     // store this if you want to remove any world-space y-axis movement
     var oldY = character.transform.position.y;
     character.transform.position += playerCamera.transform.right * moveVector.x;
     character.transform.position += playerCamera.transform.forward * moveVector.y;
     character.transform.position = new Vector3(
         character.transform.position.x,
         oldY,
         character.transform.position.z
     );
 }

  • deadzone info here: http://www.third-helix.com/2013/04/12/doing-thumbstick-dead-zones-right.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Edwardayy · Jul 12, 2016 at 03:12 AM

I've tried to put something together but I'm messing up somewhere. I'm not 100% familiar with C# so I'm having trouble putting it together. Can anyone help me out? using UnityEngine; using System.Collections; using Gvr;

 public class PlayerController : MonoBehaviour {
     
     // Update is called once per frame
     void Update () {
         if (GvrController.IsTouching) {
             Vector2 touchPos = GvrController.TouchPos;
             var forward = touchPos.y (0, .5f);
             var backward = touchPos.y (1, .5f);
             var left = touchPos.x (-1, 0f);
             var right = touchPos.x (1, .5f);
         }
     }
 }

I'm getting missing definitions errors and I'm missing something fundamental. Any help would be nice.

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

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

Any ideas in relate to a cube rolling? thank you! 0 Answers

Rigidbody velocity and AddForce overrides,Rigidbody.velocity overrides the Force 0 Answers

Help on how to code crouching? 0 Answers

Remember position for a simple player controller (Left/Right)? 0 Answers

Some problems with handmade basic player controller 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