Esempio n. 1
0
        public virtual void SetupCharacterController()
        {
            playerRigid = GetComponent <Rigidbody>();

            // Remove any Rigidbody on our root
            if (playerRigid != null)
            {
                GameObject.Destroy(playerRigid);
            }

            BNGPlayerController bng = GetComponent <BNGPlayerController>();

            if (bng)
            {
                bng.DistanceFromGroundOffset = 0f;
            }

            // Add the CharacterController
            characterController = GetComponent <CharacterController>();
            if (characterController == null)
            {
                characterController           = gameObject.AddComponent <CharacterController>();
                characterController.skinWidth = 0.001f;
                characterController.center    = new Vector3(0, -0.25f, 0);
                characterController.radius    = 0.1f;
                characterController.height    = 1.5f;
            }

            playerInitialized = true;
        }
Esempio n. 2
0
        public virtual void CheckControllerReferences()
        {
            // Component may be called while disabled, so check for references here
            if (playerController == null)
            {
                playerController = GetComponentInParent <BNGPlayerController>();
            }

            if (playerInitialized == false)
            {
                // Check CharacterController initialization
                if (ControllerType == PlayerControllerType.CharacterController && characterController == null)
                {
                    SetupCharacterController();

                    playerInitialized = true;
                }

                // Rigidbody Initialization
                if (ControllerType == PlayerControllerType.Rigidbody && playerRigid == null)
                {
                    playerRigid = GetComponent <Rigidbody>();

                    // If it is still null, then we'll need to setup the player rigid body
                    if (playerRigid == null)
                    {
                        SetupRigidbodyPlayer();
                    }
                }
            }
        }
Esempio n. 3
0
 void Awake()
 {
     character        = GetComponent <CharacterController>();
     playerController = GetComponent <OVRPlayerController>();
     cameraRig        = GetComponentInChildren <OVRCameraRig>();
     bngController    = transform.parent.GetComponent <BNGPlayerController>();
 }
Esempio n. 4
0
        void setupVariables()
        {
            input            = GetComponent <InputBridge>();
            playerController = GetComponent <BNGPlayerController>();
            controller       = GetComponentInChildren <CharacterController>();
            cameraRig        = GetComponentInChildren <OVRCameraRig>().transform;

            // Make sure teleport line is a root object
            if (TeleportLine != null)
            {
                TeleportLine.transform.parent = null;
                _initialLineWidth             = TeleportLine.startWidth;
            }

            if (CollisionLayers == 0)
            {
                Debug.Log("Teleport layer not set. Setting Default.");
                CollisionLayers = 1;
            }

            // HTC Uses a Trackpad that is recognized as a Thumbstick. Force to Hold Downmode
            if (ControlType == TeleportControls.ThumbstickRotate && input.IsHTCDevice())
            {
                Debug.Log("HTC Device detected, switching Teleport Mode to Thumbstick Down");
                ControlType = TeleportControls.ThumbstickDown;
            }

            setVariables = true;
        }
Esempio n. 5
0
        void setupVariables()
        {
            input            = InputBridge.Instance;
            playerController = GetComponent <BNGPlayerController>();
            controller       = GetComponentInChildren <CharacterController>();
            cameraRig        = playerController.CameraRig;
            fader            = cameraRig.GetComponentInChildren <ScreenFader>();

            // Make sure teleport line is a root object
            if (TeleportLine != null)
            {
                TeleportLine.transform.parent   = null;
                TeleportLine.transform.position = Vector3.zero;
                TeleportLine.transform.rotation = Quaternion.identity;

                _initialLineWidth = TeleportLine.startWidth;
            }

            if (CollisionLayers == 0)
            {
                Debug.Log("Teleport layer not set. Setting Default.");
                CollisionLayers = 1;
            }

            // HTC Uses a Trackpad that is recognized as a Thumbstick. Force to Hold Downmode
            if (ControlType == TeleportControls.ThumbstickRotate && input.IsHTCDevice)
            {
                Debug.Log("HTC Device detected, switching Teleport Mode to Thumbstick Down");
                ControlType = TeleportControls.ThumbstickDown;
            }

            setVariables = true;
        }
Esempio n. 6
0
        void Start()
        {
            mainCameraTransform = GameObject.Find("CameraRig").transform;
            leftHandAnchor      = GameObject.Find("LeftHandAnchor").transform;
            rightHandAnchor     = GameObject.Find("RightHandAnchor").transform;

            leftControllerTranform  = GameObject.Find("LeftControllerAnchor").transform;
            rightControllerTranform = GameObject.Find("RightControllerAnchor").transform;

            player = FindObjectOfType <BNGPlayerController>();

            if (player)
            {
                // Use this to keep our head up high
                player.ElevateCameraIfNoHMDPresent = true;
                _originalPlayerYOffset             = player.ElevateCameraHeight;

                smoothLocomotion = player.GetComponentInChildren <SmoothLocomotion>();

                if (smoothLocomotion == null)
                {
                    Debug.Log("No Smooth Locomotion component found. Will not be able to use SmoothLocomotion without calling it manually.");
                }
                else if (smoothLocomotion.MoveAction == null)
                {
                    Debug.Log("Smooth Locomotion Move Action has not been assigned. Make sure to assign this in the inspector if you want to be able to move around using the VR Emulator.");
                }
            }
        }
Esempio n. 7
0
 // Start is called before the first frame update
 void Start()
 {
     pControl                = GameObject.FindGameObjectWithTag("Player").GetComponentInChildren <OVRPlayerController>();
     characterController     = GameObject.FindGameObjectWithTag("Player").GetComponentInChildren <CharacterController>();
     bngController           = GameObject.FindGameObjectWithTag("Player").GetComponent <BNGPlayerController>();
     _initialGravityModifier = pControl.GravityModifier;
     audioSource             = GetComponent <AudioSource>();
 }
Esempio n. 8
0
        private float _verticalSpeed = 0; // Keep track of vertical speed

        void Start()
        {
            characterController = GetComponent <CharacterController>();
            playerController    = GetComponent <BNGPlayerController>();
            if (playerController == null)
            {
                playerController = GetComponentInParent <BNGPlayerController>();
            }
        }
Esempio n. 9
0
        public override void GrabItem(Grabber grabbedBy)
        {
            // Add the climber so we can track it's position for Character movement
            if (bngController == null)
            {
                bngController = GameObject.FindGameObjectWithTag("Player").GetComponent <BNGPlayerController>();
            }
            bngController.AddClimber(this, grabbedBy);

            base.GrabItem(grabbedBy);
        }
Esempio n. 10
0
        public virtual void CheckControllerReferences()
        {
            // Component may be called while disabled, so check for references here
            if (playerController == null)
            {
                playerController = GetComponentInParent <BNGPlayerController>();
            }

            if (characterController == null)
            {
                characterController = GetComponent <CharacterController>();
            }
        }
Esempio n. 11
0
        void Start()
        {
            mainCameraTransform     = GameObject.Find("CameraRig").transform;
            leftControllerTranform  = GameObject.Find("LeftHandAnchor").transform;
            rightControllerTranform = GameObject.Find("RightHandAnchor").transform;

            player = FindObjectOfType <BNGPlayerController>();

            // Use this to keep our head up high
            player.ElevateCameraIfNoHMDPresent = true;
            _originalPlayerYOffset             = player.ElevateCameraHeight;

            smoothLocomotion = player.GetComponentInChildren <SmoothLocomotion>();
        }
Esempio n. 12
0
        void Start()
        {
            if (GameObject.Find("CameraRig"))
            {
                mainCameraTransform = GameObject.Find("CameraRig").transform;
            }
            // Oculus Rig Setup
            else if (GameObject.Find("OVRCameraRig"))
            {
                mainCameraTransform = GameObject.Find("OVRCameraRig").transform;
            }

            leftHandAnchor  = GameObject.Find("LeftHandAnchor").transform;
            rightHandAnchor = GameObject.Find("RightHandAnchor").transform;

            leftControllerTranform  = GameObject.Find("LeftControllerAnchor").transform;
            rightControllerTranform = GameObject.Find("RightControllerAnchor").transform;

            player = FindObjectOfType <BNGPlayerController>();

            if (player)
            {
                // Use this to keep our head up high
                player.ElevateCameraIfNoHMDPresent = true;
                _originalPlayerYOffset             = player.ElevateCameraHeight;

                smoothLocomotion = player.GetComponentInChildren <SmoothLocomotion>(true);

                // initialize component if it's currently disabled
                if (smoothLocomotion != null && !smoothLocomotion.isActiveAndEnabled)
                {
                    smoothLocomotion.CheckControllerReferences();
                }

                playerTeleport = player.GetComponentInChildren <PlayerTeleport>(true);
                if (playerTeleport)
                {
                    priorStraightSetting = playerTeleport.ForceStraightArrow;
                }

                if (smoothLocomotion == null)
                {
                    Debug.Log("No Smooth Locomotion component found. Will not be able to use SmoothLocomotion without calling it manually.");
                }
                else if (smoothLocomotion.MoveAction == null)
                {
                    Debug.Log("Smooth Locomotion Move Action has not been assigned. Make sure to assign this in the inspector if you want to be able to move around using the VR Emulator.");
                }
            }
        }
Esempio n. 13
0
        void Start()
        {
            player   = GetComponent <BNGPlayerController>();
            teleport = GetComponent <PlayerTeleport>();

            // Load Locomotion Preference
            if (LoadLocomotionFromPrefs)
            {
                ChangeLocomotion(PlayerPrefs.GetInt("LocomotionSelection", 0) == 0 ? LocomotionType.Teleport : LocomotionType.SmoothLocomotion, false);
            }
            else
            {
                ChangeLocomotion(DefaultLocomotion, false);
            }
        }
Esempio n. 14
0
        // Start is called before the first frame update
        void Start()
        {
            GameObject player = GameObject.FindGameObjectWithTag("Player");

            if (player)
            {
                characterController = player.GetComponentInChildren <CharacterController>();
                bngController       = player.GetComponentInChildren <BNGPlayerController>();
                playerGravity       = player.GetComponentInChildren <PlayerGravity>();
            }
            else
            {
                Debug.Log("No player object found.");
            }

            audioSource = GetComponent <AudioSource>();
        }
Esempio n. 15
0
        void Start()
        {
            mainCameraTransform     = GameObject.Find("CameraRig").transform;
            leftControllerTranform  = GameObject.Find("LeftHandAnchor").transform;
            rightControllerTranform = GameObject.Find("RightHandAnchor").transform;

            player = FindObjectOfType <BNGPlayerController>();

            // Use this to keep our head up high
            player.ElevateCameraIfNoHMDPresent = true;
            _originalPlayerYOffset             = player.ElevateCameraHeight;

            // Only useful in the editor
            if (!Application.isEditor)
            {
                Destroy(this);
            }
        }
Esempio n. 16
0
        void Awake()
        {
            col   = GetComponent <Collider>();
            rigid = GetComponent <Rigidbody>();

            if (GameObject.FindGameObjectWithTag("Player"))
            {
                input = GameObject.FindGameObjectWithTag("Player").GetComponent <InputBridge>();
            }
            else
            {
                Debug.LogError("No InputBridge Found on Player GameObject. Make sure you have one Player with the 'Player' Tag and the InputBridge component");
            }

            events     = GetComponents <GrabbableEvents>().ToList();
            collisions = new List <Collider>();

            // Try parent if no rigid found here
            if (rigid == null && transform.parent != null)
            {
                rigid = transform.parent.GetComponent <Rigidbody>();
            }

            // Store initial rigidbody properties so we can reset them later as needed
            if (rigid)
            {
                initialCollisionMode     = rigid.collisionDetectionMode;
                initialInterpolationMode = rigid.interpolation;
                wasKinematic             = rigid.isKinematic;
                usedGravity = rigid.useGravity;
            }

            // Store initial parent so we can reset later if needed
            UpdateOriginalParent(transform.parent);

            validGrabbers = new List <Grabber>();

            OriginalScale = transform.localScale.x;

            if (GameObject.FindGameObjectWithTag("Player"))
            {
                player = GameObject.FindGameObjectWithTag("Player").GetComponentInChildren <BNGPlayerController>();
            }
        }
Esempio n. 17
0
        public virtual void SetupRigidbodyPlayer()
        {
            playerRigid                = gameObject.AddComponent <Rigidbody>();
            playerRigid.mass           = 50f;
            playerRigid.drag           = 1f;
            playerRigid.angularDrag    = 0.05f;
            playerRigid.freezeRotation = true;
            // playerRigid.useGravity = false; // Gravity is applied manually

            // Remove any CharacterControllers, if any
            CharacterController charController = GetComponent <CharacterController>();

            if (charController != null)
            {
                GameObject.Destroy(charController);
            }

            BNGPlayerController bng = GetComponent <BNGPlayerController>();

            if (bng)
            {
                bng.DistanceFromGroundOffset = -0.087f;
            }

            // Add the colliders
            CapsuleCollider cc = gameObject.AddComponent <CapsuleCollider>();

            cc.radius = 0.1f;
            cc.center = new Vector3(0, 0.785f, 0);
            cc.height = 1.25f;

            SphereCollider sc = gameObject.AddComponent <SphereCollider>();

            sc.center = new Vector3(0, 0.079f, 0);
            sc.radius = 0.08f;

            playerInitialized = true;
        }
Esempio n. 18
0
 void Start()
 {
     characterController = GameObject.FindGameObjectWithTag("Player").GetComponentInChildren <CharacterController>();
     bngController       = GameObject.FindGameObjectWithTag("Player").GetComponent <BNGPlayerController>();
     audioSource         = GetComponent <AudioSource>();
 }
Esempio n. 19
0
 void Awake()
 {
     character     = GetComponent <CharacterController>();
     bngController = transform.GetComponentInParent <BNGPlayerController>();
 }
Esempio n. 20
0
 void Start()
 {
     player = GetComponentInParent <BNGPlayerController>();
 }