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 scarcloud · Apr 09, 2018 at 06:24 PM · vrcamera-movementoculusoculusriftoculus rift

Pull OVRCameraRig over RTS map via touch controller grabbing gesture

Currently developing a little prototype RTS with the Oculus VR devkit. I want to implement camera movement via "grabbing" onto the world space with a touch controller and move the OVRCameraRig object on the X- and Z-axes. For the prototype purpose, I rather decided to go with a simpler approach, namely just pull the map around, since it's not that big, and not much is happening on it.

So far I got this script:

 public class MapMover : MonoBehaviour
 {
     private bool movementEnabled;

     Transform map;
     Transform leftController;
     Vector3 offset;

     public bool IsMovementEnabled { get { return movementEnabled; } }

     private void Awake()
     {
         leftController = GameObject.Find("LeftHandAnchor").transform;
     }

     public void BeginMovement()
     {
         offset = transform.position - leftController.position;
         movementEnabled = true;
     }

     public void EndMovement()
     {
         movementEnabled = false;
     }

     private void LateUpdate()
     {
         if (movementEnabled)
         {
             transform.position = new Vector3(
                 (leftController.position.x * 1.1f + offset.x),
                 transform.position.y,
                 (leftController.position.z * 1.1f + offset.z)
             );
         }
     }
 }

BeginMovement() is called when I press the Hand Trigger on the left Touch controller. My current results are unproductive: The first BeginMovement() call is sufficient, but the movement of the map is very minimal, since the controller models are tiny and their position clamps around -1.0f and 1.0f. The second call of BeginMovement() makes the map do a jump to either side before going back to the minimal movement.

My question is, what exactly am I missing? Is there a simpler approach to this?

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

Answer by scarcloud · Apr 15, 2018 at 01:22 PM

I have changed my approach to the problem and came up with a basic solution that supports my needs:

 public class MapMover : MonoBehaviour
 {
     private bool movementEnabled;
     private float factor = 45.0f;

     Transform leftController;

     Vector3 lastControllerPosition;
     Vector3 currentControllerPosition;

     private void Awake()
     {
         leftController = GameObject.Find("LeftHandAnchor").transform;
         currentControllerPosition = leftController.transform.position;
     }

     public void BeginMovement() { movementEnabled = true; }

     public void EndMovement() { movementEnabled = false; }

     private void Update()
     {
         lastControllerPosition = currentControllerPosition;
         currentControllerPosition = leftController.transform.position;
     }

     private void LateUpdate()
     {
         if (movementEnabled) {
             Vector3 distance = currentControllerPosition - lastControllerPosition;
             transform.Translate(distance.x * factor, 0, distance.z * factor);
         }
     }
 }


Basic function explained:

The script is a component of the map object and is initialized with the current position of the left controller's transform.position. Each frame, this value is moved to the last position, while the current position is retrieved anew. During the LateUpdate(), upon meeting the condition of being moved, the difference between current and last position is calculated, and the map object is translated by the result's X- and Z-values multiplied by a factor (after extensive testing, a factor of 45.0f seems comfortable for moving around, but you should definitely test it out to meet your needs).

I hope this will help someone.

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

167 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

Related Questions

Oculus Touch Joystick interaction 0 Answers

Unity XR Interaction Manager Bug? 1 Answer

I can't access play mode with Oculus 0 Answers

Unity Input and Oculus Rift with Touch Controllers in Unity 2018.3.7f1 1 Answer

Don't know what's causing screen splitting 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