- Home /
VR - setting up cockpit to drift slightly
Still learning unity's library,
I've got a cockpit Game Object that surrounds the player's view. The player is constantly moving forward and in the direction they're looking. To give the ship mass and some imaginary inertia, I have the cockpit set to drift 'against' whichever direction the player moves the ship.
Currently, if a player looks all the way to the right, the cockpit shifts to the left. The next step will still let the cockpit drift to the left but get 'tugged' back to recenter around wherever the player is looking. Problem is I have no idea how to get that effect after a few hours of trying different things out.
Here's the script that's dragged onto the cockpit:
public class CockpitDrift : MonoBehaviour {
public float distanceMoved = 50.0f;
public float reactiveModifier = 10.0f;
private float orientationA;
private float orientationB;
private Vector3 originalPosition;
private Vector3 newPosition;
// Saving the original position of the gameobject
void Start () {
originalPosition = transform.localPosition;
}
//Handles the drift.
void FixedUpdate() {
Quaternion headOrientation = GvrViewer.Instance.HeadPose.Orientation;
orientationA = -headOrientation.y * Time.deltaTime * distanceMoved;
orientationB = headOrientation.x * Time.deltaTime * distanceMoved;
newPosition = new Vector3(originalPosition.x + orientationA, originalPosition.y + orientationB, originalPosition.z);
transform.localPosition = Vector3.Slerp(transform.localPosition, newPosition, reactiveModifier * Time.deltaTime);
}
}
Your answer
Follow this Question
Related Questions
How to handle FPSCharacter movement using Google daydream controller touchpad? 0 Answers
[VR] CameraRig and Neck 1 Answer
Moving character relative to camera position. 1 Answer
Trying to create a camera that follows player and mimics headset tracking(HTC Vive) 1 Answer
Make VR HUD For health bar and mana. 2 Answers