Skip to main content
Up and Coming
July 6, 2015

Move in look direction

Hi,

Iam developing gear VR app with unity platform and oculus sdk.

I have the OVRPlayercontroller in the scene and this navigate well in the scene.

Now instead of interaction, how do i make the camera move in the looking direction to a specific point.

Could someone hep me out on this.

Thanks

    8 replies

    Inspiring
    July 6, 2015
    One way to do this would be to capture a position along the look vector, and then lerp from the current position.

    Here is an example of how to do this.

    - Add the following to the top of the OVRPlayerController.cs class (under the other variables around line 97):

    	private float startTime;
    private float lerpSpeed = 1.0f;
    private float lerpDist = 1.0f;
    private float lerpEnd = 0.1f;
    private bool lerpPosition = false;
    private Vector3 oldPosition;
    private Vector3 newPosition;
    private float journeyLength;


    - Then add this to the end of UpdateMovement() (around line 337):

    		if (Input.GetKeyUp (KeyCode.L)) {
    oldPosition = transform.position;
    newPosition = transform.position + transform.forward * lerpDist;
    journeyLength = Vector3.Distance(oldPosition, newPosition);
    startTime = Time.time;
    lerpPosition = true;
    }

    if (lerpPosition) {
    float distCovered = (Time.time - startTime) * lerpSpeed;
    float fracJourney = distCovered / journeyLength;
    transform.position = Vector3.Lerp(oldPosition, newPosition, fracJourney);
    if(Vector3.Distance(transform.position, newPosition) < lerpEnd) lerpPosition = false;
    }


    However, I should mention that automatically moving the camera can cause discomfort for some players and should be avoided if possible. Hope that helps.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    muralivAuthor
    Up and Coming
    July 7, 2015
    Hello
    Thanks for the code and it worked fine.
    Only thing instead of keycode "L" i changed it to touch pad tap, as i am using only the touchpad in the Gear VR device.

    The actual requirement is.

    Suppose i have gameobject in the scene with a circle texture, when i look at it or when we do a raycast so that i collides with this game object,i want to highlight and when tapped, i want to move in that direction close to that.

    Is this possible.

    Thanks in advance.
    Inspiring
    July 7, 2015
    Yes, you can. I made an example project that uses raycasting to highlight objects and a simple stereo crosshair. Unfortunately, the code is for Unity 5.1.x first-party VR, so if you are using an older version or the legacy Oculus integration you may have to modify the scripts.

    viewtopic.php?f=37&t=24752&p=284071#p284071

    It should still show the basic code of how to do it, and you can port to your own script.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    muralivAuthor
    Up and Coming
    July 8, 2015
    Ok thanks cyber,
    I will look into the code and experiment it.

    Could you please let me know whether unity 5.1 fully support oculus SDK. Because when i upgraded and tested it, there were lot of errors thrown and was not able to publish, mainly nullpointer exception errors.
    So I had to switch back to unity 4.6 version.
    Inspiring
    July 8, 2015
    The version to use is Unity 5.1.1p3 (as of today). With that you should NOT use the Oculus Unity Integration as it will conflict. All you need is a normal 2D camera, and then select "Virtual Reality Supported" in the player settings. You can also import the Oculus Unity Utilities package, as this will give you some helpful scripts but it's not needed.
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    New Participant
    July 9, 2015
    Hello Cyber,
    But without the oculus unity package import,how do I get the OVRPlayercontrol .
    Is there any other alternative for this.


    Thanks
    Inspiring
    July 9, 2015
    You would download the Unity Utilities package, which include helper classes.

    https://developer.oculus.com/downloads/ ... for_Unity/
    AMD Ryzen 7 1800X | MSI X370 Titanium | G.Skill 16GB DDR4 3200 | EVGA SuperNOVA 1000 | Corsair Hydro H110i Gigabyte RX Vega 64 x2 | Samsung 960 Evo M.2 500GB | Seagate FireCuda SSHD 2TB | Phanteks ENTHOO EVOLV
    muralivAuthor
    Up and Coming
    July 13, 2015
    Hi Cyber,

    have you seen "Herobound' in the samsung gear VR.
    The graphics quality and the text clarity
    Any idea, on what software this is done.
    is that unity.

    We have been asked to bring in that kind of quality.

    Could you please help me out so that i can work in that direction to explore more.