Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Schnigges's avatar
Schnigges
Honored Guest
11 years ago

Vertical movement in direction of camera

I'm currently trying to create some kind of virtual "fly-through" a CAD-model, and I'd like to enable movement always in direction of the camera center, thus also vertical translation of the camera (y-direction) --> exactly like the fly-through mode in Unity. I'm completely new to the Oculus SDK, so my first step was to use the Tuskany Unity 3D example and put my meshed model in there.

I've tried a couple of different changes to the OVRPlayerController.cs file (e.g. change gravity to zero), however I couldn't make it work so far. I assume some changes are necessary to the Update() method.

Can this be achieved relatively easy by slight changes to the OVRPlayerController.cs file, or are further changes necessary?

1 Reply

  • After kicking out all of the "unnecessary" code, I'm left with two main code snippets that should be responsible for the player movement inside the OVRPlayerController.cs file:

    Update():
    protected virtual void Update()
    {
    UpdateMovement();

    Vector3 moveDirection = Vector3.zero;

    float motorDamp = (1.0f + (Damping * OVRDevice.SimulationRate * Time.deltaTime));
    MoveThrottle.x /= motorDamp;
    MoveThrottle.y = (MoveThrottle.y > 0.0f) ? (MoveThrottle.y / motorDamp) : MoveThrottle.y;
    MoveThrottle.z /= motorDamp;

    moveDirection += MoveThrottle * OVRDevice.SimulationRate * Time.deltaTime;

    moveDirection.y += FallSpeed * OVRDevice.SimulationRate * Time.deltaTime;

    Vector3 predictedXZ = Vector3.Scale((Controller.transform.localPosition + moveDirection),
    new Vector3(1, 0, 1));

    // Move contoller
    Controller.Move(moveDirection);

    Vector3 actualXZ = Vector3.Scale(Controller.transform.localPosition, new Vector3(1, 0, 1));

    if (predictedXZ != actualXZ)
    MoveThrottle += (actualXZ - predictedXZ) / (OVRDevice.SimulationRate * Time.deltaTime);

    // Update rotation using CameraController transform, possibly proving some rules for
    // sliding the rotation for a more natural movement and body visual
    UpdatePlayerForwardDirTransform();
    }


    UpdateMovement():
    public virtual void UpdateMovement()
    {
    // Do not apply input if we are showing a level selection display
    if(HaltUpdateMovement == true)
    return;

    bool moveForward = false;
    bool moveLeft = false;
    bool moveRight = false;
    bool moveBack = false;

    MoveScale = 5.0f;

    // * * * * * * * * * * *
    // Keyboard input

    // Move

    // WASD
    if (Input.GetKey(KeyCode.W)) moveForward = true;
    if (Input.GetKey(KeyCode.A)) moveLeft = true;
    if (Input.GetKey(KeyCode.S)) moveBack = true;
    if (Input.GetKey(KeyCode.D)) moveRight = true;
    // Arrow keys
    if (Input.GetKey(KeyCode.UpArrow)) moveForward = true;
    if (Input.GetKey(KeyCode.LeftArrow)) moveLeft = true;
    if (Input.GetKey(KeyCode.DownArrow)) moveBack = true;
    if (Input.GetKey(KeyCode.RightArrow)) moveRight = true;

    MoveScale *= OVRDevice.SimulationRate * Time.deltaTime;

    // Compute this for key movement
    float moveInfluence = Acceleration * 0.1f * MoveScale * MoveScaleMultiplier;

    if(DirXform != null)
    {
    if (moveForward)
    MoveThrottle += DirXform.TransformDirection(Vector3.forward * moveInfluence * transform.lossyScale.z);
    if (moveBack)
    MoveThrottle += DirXform.TransformDirection(Vector3.back * moveInfluence * transform.lossyScale.z) * BackAndSideDampen;
    if (moveLeft)
    MoveThrottle += DirXform.TransformDirection(Vector3.left * moveInfluence * transform.lossyScale.x) * BackAndSideDampen;
    if (moveRight)
    MoveThrottle += DirXform.TransformDirection(Vector3.right * moveInfluence * transform.lossyScale.x) * BackAndSideDampen;
    }

    // Rotate

    // compute for key rotation
    float rotateInfluence = OVRDevice.SimulationRate * Time.deltaTime * RotationAmount * RotationScaleMultiplier;

    float deltaRotation = 0.0f;
    if(SkipMouseRotation == false)
    deltaRotation = Input.GetAxis("Mouse X") * rotateInfluence * 3.25f;

    float filteredDeltaRotation = (sDeltaRotationOld * 0.0f) + (deltaRotation * 1.0f);
    YRotation += filteredDeltaRotation;
    sDeltaRotationOld = filteredDeltaRotation;

    // Update cameras direction and rotation
    if (Input.GetKey(KeyCode.F))
    {
    Jump_Up();
    Jump_Up();
    }

    if (Input.GetKey (KeyCode.H))
    {
    Jump_Down ();
    Jump_Up();
    }

    SetCameras();
    }


    However, I still couldn't figure out how to achieve movement in exactly the same direction as the camera, especially in the y-direction. Is it possible to achieve this by changes to these two sections?

    Thanks for your help!