Ejemplo n.º 1
0
 protected void Update()
 {
     if (FpsControl.WasPressedThisFrame(FpsInput.Interact))
     {
         Activate();
     }
 }
Ejemplo n.º 2
0
        public void Process()
        {
            // Look ------------
            Vector2 lookInput = FpsControl.GetLook();

            if (_fixedInitialInputError < 10)
            {
                // skip the first frame of input to avoid a bug that causes things to jump
                if (lookInput.magnitude > 0)
                {
                    _fixedInitialInputError++;
                }
            }
            else
            {
                transform.Rotate(Vector3.up * lookInput.x * _lookSpeedX * Time.deltaTime, Space.World);
                WorldCamera.transform.Rotate(Vector3.right * lookInput.y * _lookSpeedY * -1 * Time.deltaTime, Space.Self);
            }

            // Overwrite roll accumulated from rotation with user-defined roll
            Vector3 euler = WorldCamera.transform.rotation.eulerAngles;

            euler.z = 0;
            WorldCamera.transform.rotation = Quaternion.Euler(euler);
        }
Ejemplo n.º 3
0
        public void Process(Transform cameraTransform)
        {
            Vector2 moveInput = FpsControl.GetMove();
            Vector3 forward   = cameraTransform.forward;

            // Force walk on level plane
            forward.y = 0;
            forward  *= moveInput.y * _speed;

            Vector3 right = cameraTransform.right;

            // Force walk on level plane
            right.y = 0;
            right  *= moveInput.x * _speed;

            if (UsePhysics)
            {
                // airborne
                if ((FpsHeroState)_hero.ActiveState.Name == FpsHeroState.Jump)
                {
                    Vector3 up = Vector3.up * _rigidbody.velocity.y;
                    //	_rigidbody.velocity = right + up + forward;
                }
                else
                {
                    _rigidbody.velocity = right + forward;
                }
                _rigidbody.angularVelocity = Vector3.zero;
            }
            else
            {
                transform.position += (forward + right) * Time.deltaTime;
            }
        }
Ejemplo n.º 4
0
 protected override void OnProcessEnd(float deltaTime)
 {
     if (FpsControl.WasPressedThisFrame(FpsInput.Jump))
     {
         _hero.GoToState(FpsHeroState.Jump);
     }
     else if (FpsControl.WasReleasedThisFrame(FpsInput.Run))
     {
         _hero.GoToState(FpsHeroState.Normal);
     }
 }
Ejemplo n.º 5
0
        protected override void OnProcessEnd(float deltaTime)
        {
            _hero.Look.LerpToHeight(_cameraHeight, 0.1f);

            if (FpsControl.WasPressedThisFrame(FpsInput.Jump))
            {
                _hero.GoToState(FpsHeroState.Jump);
            }
            else if (FpsControl.WasReleasedThisFrame(FpsInput.Crouch))
            {
                _hero.GoToState(FpsHeroState.Normal);
            }
        }
Ejemplo n.º 6
0
        protected override void OnProcessEnd(float deltaTime)
        {
            _hero.Look.LerpToHeight(FpsLook.BASE_HEIGHT, 0.1f);

            if (FpsControl.WasPressedThisFrame(FpsInput.Crouch))
            {
                _hero.GoToState(FpsHeroState.Crouch);
            }
            else if (FpsControl.WasPressedThisFrame(FpsInput.Jump))
            {
                _hero.GoToState(FpsHeroState.Jump);
            }
            else if (FpsControl.WasPressedThisFrame(FpsInput.Run))
            {
                _hero.GoToState(FpsHeroState.Run);
            }
            else if (FpsControl.WasPressedThisFrame(FpsInput.Sneak))
            {
                _hero.GoToState(FpsHeroState.Sneak);
            }
        }
Ejemplo n.º 7
0
        protected void Update()
        {
            // Process all projectiles. Return ones that aren't busy to the pool.
            float deltaTime = Time.deltaTime;

            foreach (FpsProjectile projectile in _projectiles)
            {
                if (projectile.IsBusy)
                {
                    projectile.Process(deltaTime);
                }
                else
                {
                    projectile.Remove();
                }
            }

            if (Time.time > _lastFiretime + _cooldown && FpsControl.IsPressed(FpsInput.Shoot))
            {
                Shoot();
            }
        }
Ejemplo n.º 8
0
        protected void OnTriggerEnter(Collider collider)
        {
            if (_hasBeenUsed || collider.gameObject.layer != _heroLayer)
            {
                return;
            }

            if (FpsHero.Instance.HasKeycard(_requiredKeycardId) == false)
            {
                FpsHud.Message.Show(_lockPrompt);
                return;
            }

            if (_automaticInteraction)
            {
                Activate();
            }
            else
            {
                FpsHud.Prompt.Show(FpsControl.GetKeyboardInput(FpsInput.Interact), _prompt);
                enabled = true;
            }
        }
Ejemplo n.º 9
0
        // Add and initialize all states
        protected void Awake()
        {
            Instance = this;

            _keycardIds = new HashSet <string>();
            _fpsStats   = GetComponent <FpsStats>();
            _fpsLook    = GetComponent <FpsLook>();
            _fpsMove    = GetComponent <FpsMove>();
            Rigidbody   = GetComponent <Rigidbody>();
            FpsControl.Initialize(shiftRunNotSneak: true);

            FpsHeroFiniteState[] states = GetComponentsInChildren <FpsHeroFiniteState>();
            _finiteStates = new Dictionary <Enum, FpsHeroFiniteState>();

            foreach (FpsHeroFiniteState state in states)
            {
                if (state.Name == null)
                {
                    Debug.LogError(this.GetType().ToString() + ".Awake: Ignored null state name on " + state.gameObject.name, gameObject);
                    continue;
                }

                if (_finiteStates.ContainsKey(state.Name) == false)
                {
                    if (PrintDebug)
                    {
                        Debug.LogFormat(this.GetType().ToString() + ".Awake: Add state {0}", state.Name);
                    }
                    _finiteStates.Add(state.Name, state);
                    state.Initialize(this);
                }
                else
                {
                    Debug.LogWarning(this.GetType().ToString() + ".Awake: Ignored duplicate state " + state.Name + " on " + state.gameObject.name, gameObject);
                }
            }
        }