Develop HTC vive--Mobile roaming chapter with Unity

Source: Internet
Author: User

This article mainly writes about moving through the joystick control to roam in the scene.
In the control of movement through the handle, I mainly wrote two scripts a ChildTransform.cs, Move.cs;
1, Childtransform This script is mainly to get the head y axis direction of rotation. And the movement of the head in the X-and z-axis direction. Assign this information to the object that the script binds to.
2, move this script is mainly to control the movement of the player, the direction of movement is based on binding childtransform this script transform information.
This can be achieved, the helmet rotation control the direction of movement, the handle touchpad the upper, lower, left, right control movement forward, left, right, backward movement.
Operation Steps:
1, first we need to first create an empty object, named Movedic.
2. Then bind the script childtransform on the movedic.
3. Assign the camera (head) to the same variable of childtransform.
This assigns the orientation information of the camera (head) to Movedic.
Script
Movie.cs has 3 public variables:
1. Player: Assign [Camera Rig] to it.
2, Dic: Assign the Movedic to it.

3, Speed: The main control of the pace of movement.

Script ChildTransform.cs:

Using unityengine;using System.collections;public class childtransform:monobehaviour{public    Transform same;// Use the For Initializationvoid Start () {}//Update is called once per framevoid Fixedupdate () {        transform.localeule Rangles = new Vector3 (0,same.localeulerangles.y,0);        Transform.localposition = new Vector3 (same.localposition.x, 0, same.localposition.z);}}

Script Move.cs:

Using unityengine;using System.collections;public class move:baseclass{//<summary>//Handle position///&LT;/S    Ummary> Steamvr_trackedobject tracked;    <summary>//player///</summary> public Transform player;    <summary>//direction///</summary> public Transform dic;    <summary>///speed//</summary> public float;    void Awake () {//get handle control tracked = Getcomponent<steamvr_trackedobject> (); }//Use this for initializationvoid Start () {}//Update is called once per framevoid Fixedupdate () {var deviceri        Ght = Steamvr_controller.input ((int) tracked.index); Press the disc key if (Deviceright. Getpress (SteamVR_Controller.ButtonMask.Touchpad)) {Vector2 cc = deviceright.            Getaxis ();            float angle = vectorangle (new Vector2 (1, 0), CC); Next if (Angle > Angle < 135) {PlayeR.translate (-dic.forward * time.deltatime * speed); }//on else if (angle < -45 && angle > -135) {//debug.log (                "On"); Player.            Translate (Dic.forward * time.deltatime * speed); }//Left else if ((Angle < && angle > 135) | |            (Angle < -135 && angle >-180))                {//debug.log ("left"); Player.            Translate (-dic.right * time.deltatime * speed); }//Right else if ((Angle > 0 && Angle < 45) | |            (Angle > -45 && angle < 0))                {//debug.log ("right"); Player.            Translate (dic.right * time.deltatime * speed); }}}///<summary>///depending on where the disc is pressed, return an angle value///</summary>//<param name= "from" ><   /param>//<param name= "to" ></param>//<returns></returns> Float Vectorangle (Vector2 from, Vector2 to) {float angle;        Vector3 cross = Vector3.cross (from, to);        Angle = Vector2.angle (from, to); Return cross.z > 0?    -angle:angle; }}

The move script is primarily based on

Deviceright. Getaxis () Gets the position information that is pressed in the touchpad and then the angle to the (0,1) point. Then according to this angle to judge in the press is touchpad the upper, lower, left and right.
In fact, Touchpad is equivalent to a circle with a radius of 1 (unit circle). and <span style= "font-family:arial, Helvetica, Sans-serif;" >getaxis () is the coordinate of the midpoint of the unit circle. </span>
Reprinted from: http://www.52vr.com/article-390-1.html

Develop HTC vive--Mobile roaming chapter with Unity

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.