示例#1
0
 void Update()
 {
     if (Input.GetButtonDown("Aux Fire"))
     {
         if (currentState == TeleportState.HIT_ENEMY && teletransportTarget == null)
         {
             currentState = TeleportState.NONE;
         }
         Debug.Log("Fire");
         if (currentState == TeleportState.HIT_ENEMY)
         {
             teletransportTarget.transform.position = transform.position;
             currentState = TeleportState.NONE;
             Destroy(this.gameObject);
         }
         else if (currentState == TeleportState.SECOND_SHOT_ENEMY)
         {
             Debug.Log("enemy teleporting");
         }
         else if (currentState == TeleportState.NONE && weeb.IsGrounded())
         {
             weeb.transform.position = transform.position;
             weeb.GetComponent <WeebPlayer>().ResetGravity();
             Destroy(this.gameObject);
         }
     }
 }
 private void EndState(TeleportState state)
 {
     if (state == TeleportState.TeleportOut)
     {
         m_shadowSprite.renderer.enabled = false;
         if (hasOutlinesDuringAnim)
         {
             SpriteOutlineManager.ToggleOutlineRenderers(m_aiActor.sprite, false);
         }
     }
     else if (state == TeleportState.TeleportIn)
     {
         if (teleportRequiresTransparency)
         {
             m_aiActor.sprite.usesOverrideMaterial = false;
             m_aiActor.renderer.material.shader    = m_cachedShader;
         }
         if (shadowSupport == ShadowSupport.Fade)
         {
             m_shadowSprite.color = m_shadowSprite.color.WithAlpha(1f);
         }
         m_aiActor.specRigidbody.CollideWithOthers = true;
         m_aiActor.IsGone = false;
         if (m_aiShooter)
         {
             m_aiShooter.ToggleGunAndHandRenderers(true, "BossFinalMarinePortalBehavior");
         }
         if (!hasOutlinesDuringAnim)
         {
             SpriteOutlineManager.ToggleOutlineRenderers(m_aiActor.sprite, true);
         }
     }
 }
示例#3
0
 public void Teleport(bool teleport, bool descend = true)
 {
     if (teleport)
     {
         isTeleporting = true;
         FreezeInput(true);
         animator.Play("Player_Teleport");
         // descending will override the state and velocity
         teleportState = TeleportState.Landed;
         rb2d.velocity = new Vector2(0, rb2d.velocity.y);
         // we can set the descend flag to false if all we want is to show
         // the teleport animation - we go straight into the Landed state
         // if true then set to Descending state and apply teleport velocity
         if (descend)
         {
             animator.speed = 0;
             teleportState  = TeleportState.Descending;
             rb2d.velocity  = new Vector2(rb2d.velocity.x, teleportSpeed);
         }
     }
     else
     {
         isTeleporting = false;
         FreezeInput(false);
     }
 }
示例#4
0
        private void UpdateTeleport()
        {
            var x = _naviSprite.AnimationGroup[_currentAnimation];

            switch (_currentTeleportState)
            {
            case TeleportState.State1:
                _currentAnimation     = "MM_TELEPORT1";
                _currentTeleportState = TeleportState.State2;
                break;

            case TeleportState.State2:
                if (!x.Active)
                {
                    _currentAnimation = "MM_TELEPORT2";
                    _row    = _newRow;
                    _column = _newCol;
                    _currentTeleportState = TeleportState.State3;
                }
                break;

            case TeleportState.State3:
                if (!x.Active)
                {
                    _currentTeleportState = TeleportState.None;
                    _naviSprite.ResetAllGroups();
                    _currentAnimation = "MM";
                }
                break;
            }
        }
示例#5
0
 override public void Collide(GameObject enemy)
 {
     Debug.Log("Hit enemy");
     currentState        = TeleportState.HIT_ENEMY;
     teletransportTarget = enemy;
     Destroy(this.gameObject);
 }
示例#6
0
 void ButtonDown()
 {
     if (state != TeleportState.Idle)
     {
         return;
     }
     state = TeleportState.Aiming;
     ParabolaRenderer.enabled = true;
 }
示例#7
0
    void Start()
    {
        //if (isLocalPlayer)
        //{
        // Disable the pointer graphic (until the user holds down on the touchpad)
        Pointer.enabled = false;

        // Ensure we mark the player as not teleporting
        CurrentTeleportState = TeleportState.None;

        // Standard plane mesh used for "fade out" graphic when you teleport
        // This way you don't need to supply a simple plane mesh in the inspector
        PlaneMesh = new Mesh();
        Vector3[] verts = new Vector3[]
        {
            new Vector3(-1, -1, 0),
            new Vector3(-1, 1, 0),
            new Vector3(1, 1, 0),
            new Vector3(1, -1, 0)
        };
        int[] elts = new int[] { 0, 1, 2, 0, 2, 3 };
        PlaneMesh.vertices  = verts;
        PlaneMesh.triangles = elts;
        PlaneMesh.RecalculateBounds();

        if (FadeMaterial != null)
        {
            FadeMaterialInstance = new Material(FadeMaterial);
        }
        // Set some standard variables
        MaterialFadeID    = Shader.PropertyToID("_Fade");
        EnabledAnimatorID = Animator.StringToHash("Enabled");

        RoomBorder = GetComponent <BorderRenderer>();

        Vector3 p0, p1, p2, p3;

        if (GetChaperoneBounds(out p0, out p1, out p2, out p3))
        {
            // Rotate to match camera rig rotation
            var originRotationMatrix = Matrix4x4.TRS(Vector3.zero, OriginTransform.rotation, Vector3.one);

            BorderPointSet p = new BorderPointSet(new Vector3[] {
                originRotationMatrix *p0,
                originRotationMatrix *p1,
                originRotationMatrix *p2,
                originRotationMatrix *p3,
                originRotationMatrix *p0,
            });
            RoomBorder.Points = new BorderPointSet[]
            {
                p
            };
        }

        RoomBorder.enabled = false;
    }
示例#8
0
    // Update is called once per frame
    void Update()
    {
        // initial screen animation - teleport from top of screen really fast
        if (isTeleporting)
        {
            switch (teleportState)
            {
            case TeleportState.Descending:
                // force this to false so the jump landed sound isn't played
                isJumping = false;
                if (isGrounded)
                {
                    teleportState = TeleportState.Landed;
                }
                break;

            case TeleportState.Landed:
                // events in the animation will be called
                animator.speed = 1;
                break;

            case TeleportState.Idle:
                Teleport(false);
                // tell the game manager the teleport is finished
                GameManager.Instance.TeleportFinished();
                break;
            }
            return;
        }

        // taking damage from projectiles, touching enemies, or other environment objects
        if (isTakingDamage)
        {
            animator.Play("Player_Hit");
            return;
        }

        // player input and movement
        // don't process any input if the game is paused and
        // there is a camera transition happening
        if (!GameManager.Instance.IsGamePaused() &&
            !GameManager.Instance.InCameraTransition())
        {
            PlayerDebugInput();
            PlayerDirectionInput();
            PlayerJumpInput();
            PlayerShootInput();
        }

        // animations and movement from input
        PlayerMovement();

        // fire selected weapon
        FireWeapon();
    }
示例#9
0
    void StartTeleport(Vector2 _direction)
    {
        velocity = Vector3.zero;

        teleporting   = true;
        teleportState = TeleportState.PRE_HANG;

        teleportTimer = teleportHangTime;
        teleportsCompleted++;
        teleportDirection = _direction;

        //play fx
        PlayTeleportEffect();
    }
示例#10
0
 void ButtonUp()
 {
     if (state != TeleportState.Aiming)
     {
         return;
     }
     if (teleportable)
     {
         state = TeleportState.Moving;
     }
     else
     {
         state = TeleportState.Idle;
     }
     ParabolaRenderer.enabled = false;
 }
示例#11
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.gameObject.tag == "Surface" && currentState == TeleportState.NONE)
     {
         //GameObject player = GameObject.FindGameObjectWithTag("Player");
         //player.GetComponent<WeebPlayer>().ResetGravity();
         //player.transform.position = transform.position;
         Destroy(this.gameObject);
     }
     else if (col.gameObject.tag == "MovableObject")
     {
         currentState        = TeleportState.HIT_ENEMY;
         teletransportTarget = col.gameObject;
         Destroy(this.gameObject);
     }
 }
示例#12
0
 public void Teleport(bool teleport)
 {
     if (teleport)
     {
         isTeleporting = true;
         FreezeInput(true);
         animator.Play("Player_Teleport");
         animator.speed = 0;
         teleportState  = TeleportState.Descending;
         rb2d.velocity  = new Vector2(rb2d.velocity.x, teleportSpeed);
     }
     else
     {
         isTeleporting = false;
         FreezeInput(false);
     }
 }
示例#13
0
    // Update is called once per frame
    void Update()
    {
        // initial screen animation - teleport from top of screen really fast
        if (isTeleporting)
        {
            switch (teleportState)
            {
            case TeleportState.Descending:
                // force this to false so the jump landed sound isn't played
                isJumping = false;
                if (isGrounded)
                {
                    teleportState = TeleportState.Landed;
                }
                break;

            case TeleportState.Landed:
                // events in the animation will be called
                animator.speed = 1;
                break;

            case TeleportState.Idle:
                Teleport(false);
                break;
            }
            return;
        }

        // taking damage from projectiles, touching enemies, or other environment objects
        if (isTakingDamage)
        {
            animator.Play("Player_Hit");
            return;
        }

        // player input and movement
        PlayerDebugInput();
        PlayerDirectionInput();
        PlayerJumpInput();
        PlayerShootInput();
        PlayerMovement();

        // fire selected weapon
        FireWeapon();
    }
示例#14
0
    // Update is called once per frame
    void Update()
    {
        if (!inputDevice.HasValue)
        {
            // FIXME: currently, cannot find controller during Start().
            // Search left controller
            //  See https://docs.unity3d.com/ja/2019.4/Manual/xr_input.html
            var devices = new List <InputDevice>();
            InputDevices.GetDevicesWithCharacteristics(
                InputDeviceCharacteristics.Left | InputDeviceCharacteristics.Controller,
                devices
                );
            if (devices.Count != 0)
            {
                inputDevice = devices[0];
            }
        }

        if (inputDevice.HasValue && inputDevice.Value.TryGetFeatureValue(CommonUsages.primaryButton, out bool buttonValue))
        {
            if (!lastButtonValue && buttonValue)
            {
                ButtonDown();
            }
            else if (lastButtonValue && !buttonValue)
            {
                ButtonUp();
            }
            lastButtonValue = buttonValue;
        }

        if (state == TeleportState.Aiming)
        {
            CastParabola(Controller.forward);
        }
        else if (state == TeleportState.Moving)
        {
            // CharacterController must be temporally disabled for teleporting
            // (See https://forum.unity.com/threads/does-transform-position-work-on-a-charactercontroller.36149/#post-4132021 )
            GetComponent <CharacterController>().enabled = false;
            transform.position = target;
            GetComponent <CharacterController>().enabled = true;
            state = TeleportState.Idle;
        }
    }
示例#15
0
    private void Update()
    {
        // If we are currently teleporting (ie handling the fade in/out transition)...
        if (CurrentTeleportState == TeleportState.Teleporting)
        {
            // Wait until half of the teleport time has passed before the next event (note: both the switch from fade
            // out to fade in and the switch from fade in to stop the animation is half of the fade duration)
            if (Time.time - TeleportTimeMarker >= TeleportFadeDuration / 2)
            {
                if (FadingIn)
                {
                    // We have finished fading in
                    CurrentTeleportState = TeleportState.None;
                }
                else
                {
                    // We have finished fading out - time to teleport!
                    Vector3 offset = OriginTransform.position - HeadTransform.position;
                    offset.y = 0;
                    OriginTransform.position = Pointer.SelectedPoint + offset;
                }

                TeleportTimeMarker = Time.time;
                FadingIn           = !FadingIn;
            }
        }
        // At this point, we are NOT actively teleporting.  So now we care about controller input.
        else if (CurrentTeleportState == TeleportState.Selecting)
        {
            Debug.Assert(ActiveController != null);

            // Here, there is an active controller - that is, the user is holding down on the trackpad.
            // Poll controller for pertinent button data
            int  index          = (int)ActiveController.index;
            var  device         = SteamVR_Controller.Input(index);
            bool shouldTeleport = device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger);
            bool shouldCancel   = device.GetPressUp(SteamVR_Controller.ButtonMask.Grip);
            if (shouldTeleport || shouldCancel)
            {
                // If the user has decided to teleport (ie lets go of touchpad) then remove all visual indicators
                // related to selecting things and actually teleport
                // If the user has decided to cancel (ie squeezes grip button) then remove visual indicators and do nothing
                if (shouldTeleport && Pointer.PointOnNavMesh)
                {
                    // Begin teleport sequence
                    CurrentTeleportState = TeleportState.Teleporting;
                    TeleportTimeMarker   = Time.time;
                }
                else
                {
                    CurrentTeleportState = TeleportState.None;
                }

                // Reset active controller, disable pointer, disable visual indicators
                ActiveController   = null;
                Pointer.enabled    = false;
                RoomBorder.enabled = false;
                //RoomBorder.Transpose = Matrix4x4.TRS(OriginTransform.position, Quaternion.identity, Vector3.one);
                if (NavmeshAnimator != null)
                {
                    NavmeshAnimator.SetBool(EnabledAnimatorID, false);
                }

                Pointer.transform.parent     = null;
                Pointer.transform.position   = Vector3.zero;
                Pointer.transform.rotation   = Quaternion.identity;
                Pointer.transform.localScale = Vector3.one;
            }
            else
            {
                // The user is still deciding where to teleport and has the touchpad held down.
                // Note: rendering of the parabolic pointer / marker is done in ParabolicPointer
                Vector3 offset = HeadTransform.position - OriginTransform.position;
                offset.y = 0;

                // Render representation of where the chaperone bounds will be after teleporting
                RoomBorder.enabled   = Pointer.PointOnNavMesh;
                RoomBorder.Transpose = Matrix4x4.TRS(Pointer.SelectedPoint - offset, Quaternion.identity, Vector3.one);

                // Haptic feedback click every [HaptickClickAngleStep] degrees
                if (Pointer.CurrentParabolaAngleY >= 45) // Don't click when at max degrees
                {
                    LastClickAngle = Pointer.CurrentPointVector;
                }

                float angleClickDiff = Vector3.Angle(LastClickAngle, Pointer.CurrentPointVector);
                if (IsClicking && Mathf.Abs(angleClickDiff) > HapticClickAngleStep)
                {
                    LastClickAngle = Pointer.CurrentPointVector;
                    if (Pointer.PointOnNavMesh)
                    {
                        device.TriggerHapticPulse();
                    }
                }

                // Trigger a stronger haptic pulse when "entering" a teleportable surface
                if (Pointer.PointOnNavMesh && !IsClicking)
                {
                    IsClicking = true;
                    device.TriggerHapticPulse(750);
                    LastClickAngle = Pointer.CurrentPointVector;
                }
                else if (!Pointer.PointOnNavMesh && IsClicking)
                {
                    IsClicking = false;
                }
            }
        }
        else //CurrentTeleportState == TeleportState.None
        {
            // At this point the user is not holding down on the touchpad at all or has canceled a teleport and hasn't
            // let go of the touchpad.  So we wait for the user to press the touchpad and enable visual indicators
            // if necessary.
            foreach (SteamVR_TrackedObject obj in Controllers.Select(hand => hand.GetComponent <SteamVR_TrackedObject>()))
            {
                int index = (int)obj.index;
                if (index == -1)
                {
                    continue;
                }

                var device = SteamVR_Controller.Input(index);
                if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
                {
                    // Set active controller to this controller, and enable the parabolic pointer and visual indicators
                    // that the user can use to determine where they are able to teleport.
                    ActiveController = obj;

                    Pointer.transform.parent        = obj.transform;
                    Pointer.transform.localPosition = Vector3.zero;
                    Pointer.transform.localRotation = Quaternion.identity;
                    Pointer.transform.localScale    = Vector3.one;
                    Pointer.enabled = true;

                    CurrentTeleportState = TeleportState.Selecting;

                    if (NavmeshAnimator != null)
                    {
                        NavmeshAnimator.SetBool(EnabledAnimatorID, true);
                    }

                    Pointer.ForceUpdateCurrentAngle();
                    LastClickAngle = Pointer.CurrentPointVector;
                    IsClicking     = Pointer.PointOnNavMesh;
                }
            }
        }
    }
示例#16
0
    // Update is called once per frame
    private void Update()
    {
        if (GameController.GameState != State.Invalid && GameController.GameState != State.Loading) //Not loading or errored
        {
            //Fetch device states
            try
            {
                leftDevice  = SteamVR_Controller.Input((int)leftTrackedObject.index);
                rightDevice = SteamVR_Controller.Input((int)rightTrackedObject.index);
            }
            catch (IndexOutOfRangeException)
            {
                return;
            }

            //Turn controls only work when the game is in the Running and Main Menu phases
            if (GameController.GameState == State.Running || GameController.GameState == State.MainMenu)
            {
                //Debug.Log("Normal Input Active");
                Transform LNearest = GetNearestTurnable(LeftObject);
                if (leftDevice.GetPressDown(EVRButtonId.k_EButton_A) && Vector3.Distance(LeftObject.transform.position, LNearest.position) <= activationDistance)
                {
                    //Debug.Log("Attempting to turn " + LNearest + " left");
                    LNearest.GetComponent <ITurnable>().TurnLeft();
                }

                Transform RNearest = GetNearestTurnable(RightObject);
                if (rightDevice.GetPressDown(EVRButtonId.k_EButton_A) && Vector3.Distance(RightObject.transform.position, RNearest.position) <= activationDistance)
                {
                    //Debug.Log("Attempting to turn " + RNearest + " right");
                    RNearest.GetComponent <ITurnable>().TurnRight();
                }

                if (leftDevice.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu) || rightDevice.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu))
                {
                    GameController.PauseGame();
                }
            }
            else if (GameController.GameState == State.Paused)
            {
                //Debug.Log("Menu Input Active");
                if (leftDevice.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu) || rightDevice.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu))
                {
                    GameController.ResumeGame();
                }
                if (rightDevice.GetPressDown(EVRButtonId.k_EButton_SteamVR_Trigger) && GetComponent <UIManager>().SelectedButton != null)
                {
                    GetComponent <UIManager>().SelectedButton.OnSubmit(new BaseEventData(GetComponent <UIManager>().SelectedButton.transform.parent.parent.GetComponent <EventSystem>()));
                }
            }

            Vector2    stickValue    = leftDevice.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);
            Vector3    movementValue = new Vector3(stickValue.x, 0, stickValue.y);
            GameObject head          = CamRig.transform.Find("Camera (eye)").gameObject;
            movementValue   = (head.transform.rotation * movementValue).normalized;
            movementValue.y = 0;
            movementValue.Normalize();
            CamRig.GetComponent <Rigidbody>().velocity = movementValue * speed;

            //If TP system isn't resetting
            if (teleportState != TeleportState.Deactivating)
            {
                //If one is pushed and the other isn't
                if (leftDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad) ^ rightDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad))
                {
                    //If left is pushed
                    if (leftDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad))
                    {
                        teleportState = TeleportState.LTargeting;
                        ShowArc(leftObject);
                        //Show Arc L
                    }
                    //If button is released and we're targeting left
                    if (leftDevice.GetPressUp(EVRButtonId.k_EButton_SteamVR_Touchpad) && teleportState == TeleportState.LTargeting)
                    {
                        //Teleport L
                    }

                    //If right is pushed
                    if (rightDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad))
                    {
                        teleportState = TeleportState.RTargeting;
                        ShowArc(rightObject);
                        //Show Arc R
                    }
                    //If the button is released and we're targeting right
                    if (rightDevice.GetPressUp(EVRButtonId.k_EButton_SteamVR_Touchpad) && teleportState == TeleportState.RTargeting)
                    {
                        //Teleport R
                    }
                }
                //If both are pushed
                else if (leftDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad) && rightDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad))
                {
                    //Set to deactivate
                    teleportState = TeleportState.Deactivating;
                }
            }
            if (teleportState == TeleportState.Deactivating)
            {
                if (!leftDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad) && !rightDevice.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad))
                {
                    teleportState = TeleportState.Inactive;
                }
            }
        }
    }
    void Update()
    {
        // If we are currently teleporting (ie handling the fade in/out transition)...
        if (CurrentTeleportState == TeleportState.Teleporting)
        {
            // Wait until half of the teleport time has passed before the next event (note: both the switch from fade
            // out to fade in and the switch from fade in to stop the animation is half of the fade duration)
            if (Time.time - TeleportTimeMarker >= TeleportFadeDuration / 2)
            {
                if (FadingIn)
                {
                    // We have finished fading in
                    CurrentTeleportState = TeleportState.None;
                }
                else
                {
                    // We have finished fading out - time to teleport!
                    Vector3 offset = OriginTransform.position - HeadTransform.position;
                    offset.y = 0;
                    Debug.Log("Teleporting");
                    OriginTransform.position = Pointer.SelectedPoint + offset;
                }

                TeleportTimeMarker = Time.time;
                FadingIn           = !FadingIn;
            }
        }
        // At this point, we are NOT actively teleporting.  So now we care about controller input.
        else if (CurrentTeleportState == TeleportState.Selecting)
        {
            Debug.Assert(ActiveController != null);

            // Here, there is an active controller - that is, the user is holding down on the trackpad.
            // Poll controller for pertinent button data
            int  index          = (int)ActiveController.index;
            var  device         = SteamVR_Controller.Input(index);
            bool shouldTeleport = device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad);
            bool shouldCancel   = device.GetPressUp(SteamVR_Controller.ButtonMask.Grip);
            if (shouldTeleport || shouldCancel)
            {
                // If the user has decided to teleport (ie lets go of touchpad) then remove all visual indicators
                // related to selecting things and actually teleport
                // If the user has decided to cancel (ie squeezes grip button) then remove visual indicators and do nothing
                if (shouldTeleport && Pointer.PointOnNavMesh)
                {
                    /*
                     * // Begin teleport sequence
                     * CurrentTeleportState = TeleportState.Teleporting;
                     * TeleportTimeMarker = Time.time;
                     */
                    PortalObject.SetActive(true);

                    CurrentTeleportState = TeleportState.None;


                    //position of player head
                    Vector3 headPosition = HeadTransform.position;

                    Vector3 playerToCenter = OriginTransform.position - headPosition;
                    playerToCenter.y = 0;

                    Vector3 hmdDirection = HeadTransform.forward;
                    hmdDirection.y = 0;

                    Vector3 portalSpawnDirection = Vector3.RotateTowards(hmdDirection, playerToCenter, PortalMaxAngleOffset / 180 * Mathf.PI, 0);
                    portalSpawnDirection.Normalize();

                    //move portal
                    //PortalTransform.position = HeadTransform.position + (HeadTransform.forward * 1f) - new Vector3(0, 1.0f, 0);//headPosition + teleportDirection;
                    PortalTransform.position = HeadTransform.position + (portalSpawnDirection * PortalDistanceFromPlayer);
                    PortalTransform.position = new Vector3(PortalTransform.position.x, PortalHeight, PortalTransform.position.z);
                    //direction from portal to player as unit vector
                    Vector3 portalDirectionToPlayer = HeadTransform.position - PortalTransform.position;
                    portalDirectionToPlayer.y = 0;
                    portalDirectionToPlayer.Normalize();

                    //orient portal towards player
                    Quaternion rotation = Quaternion.LookRotation(-portalDirectionToPlayer);
                    PortalTransform.rotation = rotation * Quaternion.Euler(0, 0, 0);

                    //portal destination transform which is used elsewhere to orient the portal surface camera

                    /*PortalDestination.position = Pointer.SelectedPoint;
                     * var headPos = HeadTransform.rotation;
                     * headPos.x = 0.0f;
                     * headPos.z = 0.0f;
                     * PortalDestination.rotation = headPos;*/

                    PortalDestination.transform.position = Pointer.SelectedPoint;

                    //PortalDestination.transform.rotation = Quaternion.LookRotation(-new Vector3(HeadTransform.position.x, 0, HeadTransform.position.z) + new Vector3(Pointer.SelectedPoint.x, 0, Pointer.SelectedPoint.z));
                    //Quaternion portalDestinationLookRotation = Quaternion.LookRotation(-new Vector3(HeadTransform.position.x, 0, HeadTransform.position.z) + new Vector3(Pointer.SelectedPoint.x, 0, Pointer.SelectedPoint.z));
                    //Quaternion playerToCenterQuat = Quaternion.LookRotation(playerToCenter);
                    //float angleBetween = Quaternion.Angle(portalDestinationLookRotation, playerToCenter);

                    Vector3 portalDestinationLookRotation = -new Vector3(HeadTransform.position.x, 0, HeadTransform.position.z) + new Vector3(Pointer.SelectedPoint.x, 0, Pointer.SelectedPoint.z);

                    float sign = Mathf.Sign(Vector3.Dot(Vector3.up, Vector3.Cross(portalDestinationLookRotation, playerToCenter)));

                    Quaternion portalDestinationLookRotationQuat = Quaternion.LookRotation(-new Vector3(HeadTransform.position.x, 0, HeadTransform.position.z) + new Vector3(Pointer.SelectedPoint.x, 0, Pointer.SelectedPoint.z));
                    Quaternion playerToCenterQuat = Quaternion.LookRotation(playerToCenter);

                    float angleBetweenPortalDestinationLookAndPlayerToCenter = Quaternion.Angle(portalDestinationLookRotationQuat, playerToCenterQuat);

                    if (angleBetweenPortalDestinationLookAndPlayerToCenter >= PortalCameraAngleOffset + PortalMaxAngleOffset)
                    {
                        //Debug.Log("in if");
                        if (sign == 0)
                        {
                            Debug.Log(sign);
                        }
                        else if (sign > 0)
                        {
                            Quaternion portalDestinationRotate = Quaternion.AngleAxis(-PortalCameraAngleOffset, Vector3.up);
                            PortalDestination.transform.rotation = portalDestinationLookRotationQuat * portalDestinationRotate;
                        }
                        else
                        {
                            Quaternion portalDestinationRotate = Quaternion.AngleAxis(PortalCameraAngleOffset, Vector3.up);
                            PortalDestination.transform.rotation = portalDestinationLookRotationQuat * portalDestinationRotate;
                        }
                    }
                    else if (angleBetweenPortalDestinationLookAndPlayerToCenter > PortalMaxAngleOffset)
                    {
                        //do portal camera rotation up to angleBetweenPortalDestinationLookAndPlayerToCenter
                        Debug.Log("in else");
                        if (sign == 0)
                        {
                            Debug.Log(sign);
                        }
                        else if (sign > 0)
                        {
                            Quaternion portalDestinationRotate = Quaternion.AngleAxis(-(angleBetweenPortalDestinationLookAndPlayerToCenter - PortalMaxAngleOffset), Vector3.up);
                            PortalDestination.transform.rotation = portalDestinationLookRotationQuat * portalDestinationRotate;
                        }
                        else
                        {
                            Quaternion portalDestinationRotate = Quaternion.AngleAxis(angleBetweenPortalDestinationLookAndPlayerToCenter - PortalMaxAngleOffset, Vector3.up);
                            PortalDestination.transform.rotation = portalDestinationLookRotationQuat * portalDestinationRotate;
                        }
                    }
                    else if (angleBetweenPortalDestinationLookAndPlayerToCenter <= PortalMaxAngleOffset)
                    {
                        //do not turn camera
                        Debug.Log("Do not turn camera");
                    }
                    //PortalDestination.transform.rotation = Quaternion.RotateTowards(portalDestinationLookRotationQuat, playerToCenterQuat, -PortalCameraAngleOffset / 180 * Mathf.PI);


                    //PortalDestination.transform.rotation = Quaternion.LookRotation(-new Vector3(HeadTransform.position.x, 0, HeadTransform.position.z) + new Vector3(Pointer.SelectedPoint.x, 0, Pointer.SelectedPoint.z));
                    // Debug.Log(stereoRenderer.m_canvasOriginWorldPosition);
                    stereoRenderer.m_canvasOriginWorldPosition = PortalTransform.position;
                    // stereoRenderer.m_canvasOriginWorldRotation = new Vector3(0.0f, 0.0f, 0.0f);
                    // stereoRenderer.m_canvasOriginWorldPosition = new Vector3(0.0f, 0.0f, 0.0f);
                    stereoRenderer.m_canvasOriginWorldRotation = PortalTransform.rotation.eulerAngles;
                    Debug.Log(stereoRenderer.m_canvasOriginWorldPosition);

                    Debug.Log(Pointer.SelectedPoint);
                }
                else
                {
                    CurrentTeleportState = TeleportState.None;
                }

                // Reset active controller, disable pointer, disable visual indicators
                ActiveController   = null;
                Pointer.enabled    = false;
                RoomBorder.enabled = false;
                //RoomBorder.Transpose = Matrix4x4.TRS(OriginTransform.position, Quaternion.identity, Vector3.one);
                if (NavmeshAnimator != null)
                {
                    NavmeshAnimator.SetBool(EnabledAnimatorID, false);
                }

                Pointer.transform.parent     = null;
                Pointer.transform.position   = Vector3.zero;
                Pointer.transform.rotation   = Quaternion.identity;
                Pointer.transform.localScale = Vector3.one;
            }
            else
            {
                // The user is still deciding where to teleport and has the touchpad held down.
                // Note: rendering of the parabolic pointer / marker is done in ParabolicPointer
                Vector3 offset = HeadTransform.position - OriginTransform.position;
                offset.y = 0;

                // Render representation of where the chaperone bounds will be after teleporting
                RoomBorder.enabled   = Pointer.PointOnNavMesh;
                RoomBorder.Transpose = Matrix4x4.TRS(Pointer.SelectedPoint - offset, Quaternion.identity, Vector3.one);

                // Haptic feedback click every [HaptickClickAngleStep] degrees
                float angleClickDiff = Pointer.CurrentParabolaAngle - LastClickAngle;
                if (Mathf.Abs(angleClickDiff) > HapticClickAngleStep)
                {
                    LastClickAngle = Pointer.CurrentParabolaAngle;
                    device.TriggerHapticPulse();
                }
            }
        }
        else //CurrentTeleportState == TeleportState.None
        {
            // At this point the user is not holding down on the touchpad at all or has canceled a teleport and hasn't
            // let go of the touchpad.  So we wait for the user to press the touchpad and enable visual indicators
            // if necessary.
            foreach (SteamVR_TrackedObject obj in Controllers)
            {
                int index = (int)obj.index;
                if (index == -1)
                {
                    continue;
                }

                var device = SteamVR_Controller.Input(index);
                if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
                {
                    // Set active controller to this controller, and enable the parabolic pointer and visual indicators
                    // that the user can use to determine where they are able to teleport.
                    ActiveController = obj;

                    Pointer.transform.parent        = obj.transform;
                    Pointer.transform.localPosition = Vector3.zero;
                    Pointer.transform.localRotation = Quaternion.identity;
                    Pointer.transform.localScale    = Vector3.one;
                    Pointer.enabled = true;

                    CurrentTeleportState = TeleportState.Selecting;

                    if (NavmeshAnimator != null)
                    {
                        NavmeshAnimator.SetBool(EnabledAnimatorID, true);
                    }

                    Pointer.ForceUpdateCurrentAngle();
                    LastClickAngle = Pointer.CurrentParabolaAngle;
                }
            }
        }



        //place camera in proper position. player offset from portal is same as portal camera position offset from pointer pointed location

        /* Vector3 portalCameraOffset = PortalTransform.position - HeadTransform.position;
         * portalCameraOffset.y = 0;
         * PortalCamera.position = Pointer.SelectedPoint - portalCameraOffset + new Vector3(0, HeadTransform.position.y, 0);
         *
         * //direction from player to portal as unit vector
         * Vector3 directionPlayerToPortal = PortalTransform.position - HeadTransform.position;
         * directionPlayerToPortal.Normalize();
         *
         * //orient portal camera towards portal
         * Quaternion portalCameraRotation = Quaternion.LookRotation(directionPlayerToPortal);
         * PortalCamera.rotation = portalCameraRotation;*/
    }
        protected override void PostItemContainerTick()
        {
            base.PostItemContainerTick();

            // Keep loading item
            if( CurrentState == TeleportState.Default ){
                // Wait until fully loaded
                foreach( var status in ItemContainer.ThingStatus ){
                    var progress = ( float )status.Counter / BeltSpeed;
                    if( progress > 0.5f ){
                        CurrentState = TeleportState.Teleporting;
                    }
                }
                return;
            }

            // No target
            if( Receiver == null ){
                PowerComponent.PowerOutput = -PowerComponent.props.basePowerConsumption;
                return;
            }

            // Adjust power
            float dist = ( float )Math.Sqrt( Receiver.parent.Position.DistanceToSquared( parent.Position ) );
            float power = dist * A2BTeleportData.Power.WattsPerCell;

            PowerComponent.PowerOutput = -( A2BTeleportData.Power.BasePowerConsumption + power );

            // Push heat and throw motes until teleport complete
            if( Gen.IsHashIntervalTick( this.parent, 30 ) ){
                Room room = GridsUtility.GetRoom( parent.Position );
                if( room != null ){
                    //var dist = (float) Math.Sqrt(Receiver.parent.Position.DistanceToSquared(parent.Position));
                    float heat = dist * A2BTeleportData.Heat.DegreesPerCell;
                    room.PushHeat( heat );
                }

                int minPuffs = ( A2BTeleportData.Heat.isResearched ? 2 : 4 );
                int maxPuffs = ( A2BTeleportData.Heat.isResearched ? 2 : 6 );

                for( int i = 0; i < Rand.RangeInclusive( minPuffs, maxPuffs ); ++i )
                    MoteThrower.ThrowAirPuffUp( parent.DrawPos );

                for( int i = 0; i < Rand.RangeInclusive( minPuffs, maxPuffs ); ++i )
                    MoteThrower.ThrowAirPuffUp( Gen.TrueCenter( Receiver.parent.Position, parent.Rotation, new IntVec2( 2, 1 ), 0.5f ) );

            }

            if( !ItemContainer.WorkToDo || Random.Range( 0.0f, 1.0f ) > 0.15f )
                return;

            MoteThrower.ThrowLightningGlow( parent.DrawPos + 0.5f * GetRotationOffset(), Random.Range( 0.2f, 0.4f ) );
        }
        // Unlock the receiver after the item finishes.
        public override void OnItemTransfer( Thing item, BeltComponent other )
        {
            base.OnItemTransfer( item, other );

            BeltReceiverComponent recv = other as BeltReceiverComponent;

            // Play a nice teleport sound
            var sound = DefDatabase<SoundDef>.GetNamed( "A2B_Teleport" );
            sound.PlayOneShot( SoundInfo.InWorld( parent.Position ) );
            sound.PlayOneShot( SoundInfo.InWorld( recv.parent.Position ) );

            // And blind anyone who's looking
            MoteThrower.ThrowLightningGlow( parent.DrawPos, Random.Range( 4.8f, 5.2f ) );
            MoteThrower.ThrowLightningGlow( Receiver.parent.DrawPos, Random.Range( 4.8f, 5.2f ) );

            // Reset power usage and mode
            PowerComponent.PowerOutput = -PowerComponent.props.basePowerConsumption;
            CurrentState = TeleportState.Default;
            Receiver.Unlock( this );
        }
示例#20
0
    void CalculateVelocity()
    {
        if (stunned)
        {
            velocity.x = Mathf.SmoothDamp(velocity.x, 0, ref velocityXSmoothing, accelerationTimeStun);

            if (Time.time > endStunTime - 0.3f)
            {
                if (recovering)
                {
                    if (controller.collisions.below)
                    {
                        recovering = false;
                    }

                    float stunGradient = Time.time - endStunTime;

                    //targetVelocityX = directionalInput.x * moveSpeed;
                    velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, Mathf.Lerp(accelerationTimeStun, accelerationTimeGrounded, stunGradient * 0.3f));

                    if (stunGradient > 0.3f)
                    {
                        recovering = false;
                        EndStun();
                    }
                }
                else
                {
                    recovering = true;
                }
            }

            if (controller.collisions.left || controller.collisions.right)
            {
                velocity.y     += Mathf.Sign(velocity.y) * Mathf.Abs(velocity.x) * 0.3f;
                velocity.x      = (isStunned) ? -velocity.x * 0.3f : -velocity.x * 0.5f; //what % of your speed you retain after befoing knocked against the wall
                targetVelocityX = -targetVelocityX;

                //play rebound sound
                AudioManager.instance.PlaySound("Rebound", Vector3.zero);
            }


            velocity.y += gravity * 0.85f * Time.fixedDeltaTime;
            if (velocity.y < -terminalVelocity)
            {
                velocity.y = -terminalVelocity;
            }
        }
        else if (teleporting)
        {
            teleportTimer -= Time.fixedDeltaTime;

            switch (teleportState)
            {
            case TeleportState.PRE_HANG:

                velocity = Vector3.zero;

                if (teleportTimer <= 0)
                {
                    teleportState = TeleportState.TELEPORTING;
                    teleportTimer = teleportTime;
                    controller.SetDeadMask();
                }

                break;

            case TeleportState.TELEPORTING:

                velocity = teleportDirection * teleportMoveSpeed;

                if (teleportTimer <= 0)
                {
                    teleportState = TeleportState.POST_HANG;
                    teleportTimer = teleportHangTime;
                    controller.SetAliveMask();
                    PlayTeleportEffect();
                }

                break;

            case TeleportState.POST_HANG:

                velocity = Vector3.zero;

                if (teleportTimer <= 0)
                {
                    EndTeleport();
                }

                break;

            default:
                break;
            }
        }
        else if (dashing)
        {
            if (controller.collisions.left || controller.collisions.right)
            {
                StopDashing();
            }

            currentDashSpeed = Mathf.SmoothDamp(currentDashSpeed, targetDashSpeed, ref currentDashSpeedSmoothing, (targetDashSpeed != 0) ? accelerationTimeDash : deccelerationTimeDash / 1.5f);
            velocity         = new Vector2(targetDashDirection.x * currentDashSpeed, velocity.y);

            if (velocity.y < 1f)
            {
                velocity.y = -0.5f;
            }

            if ((faceDir > 0) ? controller.collisions.right : controller.collisions.left)
            {
                //StopDashing ();
                //velocity = new Vector2 (-velocity.x, 40f);
                //velocity /= 3;
            }
        }
        else if (hovering)
        {
            if (canHoverX && canHoverY)
            {
                directionalInput.Normalize();
            }


            if (canHoverX)
            {
                targetVelocityX = directionalInput.x * ((controller.collisions.below ? moveSpeed : airMoveSpeed) + (hat.isCurrentlyAttached ? 0 : hatlessMoveBonus) + (isHovering ? hoverMoveBonusX : 0));
                velocity.x      = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, accelerationTimeHover);
            }
            else
            {
                velocity.x = 0;
            }

            if (canHoverY)
            {
                if (directionalInput.y < 0.3 && canHoverJump)
                {
                    targetVelocityY    = hoverImpulse;
                    hoverImpulseTimer += Time.fixedDeltaTime;

                    if (hoverImpulseTimer > totalHoverImpulseTime)
                    {
                        canHoverJump      = false;
                        hoverImpulseTimer = 0;
                    }
                }
                else
                {
                    targetVelocityY = directionalInput.y * ((controller.collisions.below ? moveSpeed : airMoveSpeed) + (hat.isCurrentlyAttached ? 0 : hatlessMoveBonus) + (isHovering ? hoverMoveBonusY : 0));
                }

                velocity.y = Mathf.SmoothDamp(velocity.y, targetVelocityY, ref velocityYSmoothing, accelerationTimeHover);
            }
            else
            {
                velocity.y = 0;
            }


            if (timeToStopHovering > 0.0f)
            {
                timeToStopHovering -= Time.fixedDeltaTime;
            }
            else
            {
                hovering = false;

                if (canHoverY)
                {
                    velocity.y = Mathf.Sign(velocity.y);
                }
            }
        }
        else
        {
            targetVelocityX = directionalInput.x * ((controller.collisions.below ? moveSpeed : airMoveSpeed) + (hat.isCurrentlyAttached ? 0 : hatlessMoveBonus) + (isHovering ? hoverMoveBonusX : 0));

            if (controller.collisions.below && isSliding)
            {
                targetVelocityX *= ICE_FRICTION_MODIFIER;
            }

            //should not dash if the player is collising
            if (!controller.collisions.left && !controller.collisions.right)
            {
                if (((velocity.x == 0 && targetVelocityX != 0)) && controller.collisions.below && Mathf.Abs(directionalInput.x) > 0.6f)
                {
                    StartDashing();
                }
                else if (Mathf.Sign(directionalInput.x) != Mathf.Sign(velocity.x) && directionalInput.x != 0 && controller.collisions.below && Mathf.Abs(directionalInput.x) > 0.6f)
                {
                    StartDashing();
                }
                else if (Mathf.Sign(directionalInput.x) == Mathf.Sign(velocity.x) && Mathf.Abs(velocity.x) < Mathf.Abs(moveSpeed * 0.9f) && controller.collisions.below && Mathf.Abs(directionalInput.x) > 0.8f && !gotBoost)
                {
                    StartDashing();
                    gotBoost = true;
                }
            }

            if (Mathf.Sign(directionalInput.x) != Mathf.Sign(velocity.x) || Mathf.Abs(directionalInput.x) < 0.2f)
            {
                gotBoost = false;
            }

            velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below) ? accelerationTimeGrounded : accelerationTimeAirborne);

            if (velocity.y > 0 && (isPressingA || isBouncing))
            {
                velocity.y += gravity * Time.fixedDeltaTime;
            }
            else
            {
                isBouncing = false;
                float isFastFalling = (directionalInput.y <= -0.4) ? 1 : 0;
                velocity.y += (gravity + (isFastFalling * (fastFallFactor - 1)) * gravity) * Time.fixedDeltaTime;

                if (isFastFalling != 0 && !controller.collisions.below)
                {
                    fastFalling = true;
                }
            }

            if (velocity.y < (fastFalling ? -terminalVelocityFastFall : -terminalVelocity))
            {
                velocity.y = (fastFalling ? -terminalVelocityFastFall : -terminalVelocity);

                if (usingDifferentFallSpeeds && directionalInput.y >= -0.4)
                {
                    velocity.y  = -terminalVelocity;
                    fastFalling = false;
                }

                PlayFastFallEffect();
            }
        }
    }
示例#21
0
 // called at the end of the animation event to move to the Idle state
 // and play the landing sound (once)
 void TeleportAnimationEnd()
 {
     teleportState = TeleportState.Idle;
 }
 private void BeginState(TeleportState state)
 {
     if (state == TeleportState.TeleportOut)
     {
         if (teleportRequiresTransparency)
         {
             m_cachedShader = m_aiActor.renderer.material.shader;
             m_aiActor.sprite.usesOverrideMaterial = true;
             m_aiActor.renderer.material.shader    = ShaderCache.Acquire("Brave/LitBlendUber");
         }
         m_aiAnimator.PlayUntilCancelled(teleportOutAnim, true, null, -1f, false);
         if (shadowSupport == ShadowSupport.Animate)
         {
             m_shadowSprite.spriteAnimator.PlayAndForceTime(shadowOutAnim, m_aiAnimator.CurrentClipLength);
         }
         m_aiActor.ClearPath();
         if (!AttackableDuringAnimation)
         {
             m_aiActor.specRigidbody.CollideWithOthers = false;
             m_aiActor.IsGone = true;
         }
         if (m_aiShooter)
         {
             m_aiShooter.ToggleGunAndHandRenderers(false, "ExpandParasiteBossPortalBehavior");
         }
         if (!hasOutlinesDuringAnim)
         {
             SpriteOutlineManager.ToggleOutlineRenderers(m_aiActor.sprite, false);
         }
     }
     else if (state == TeleportState.Gone)
     {
         if (GoneTime <= 0f)
         {
             State = TeleportState.TeleportIn;
             return;
         }
         m_timer = GoneTime;
         m_aiActor.specRigidbody.CollideWithOthers = false;
         m_aiActor.IsGone = true;
         m_aiActor.sprite.renderer.enabled = false;
     }
     else if (state == TeleportState.TeleportIn)
     {
         DoTeleport();
         m_aiAnimator.PlayUntilFinished(teleportInAnim, true, null, -1f, false);
         if (shadowSupport == ShadowSupport.Animate)
         {
             m_shadowSprite.spriteAnimator.PlayAndForceTime(shadowInAnim, m_aiAnimator.CurrentClipLength);
         }
         m_shadowSprite.renderer.enabled = true;
         if (AttackableDuringAnimation)
         {
             m_aiActor.specRigidbody.CollideWithOthers = true;
             m_aiActor.IsGone = false;
         }
         m_aiActor.sprite.renderer.enabled = true;
         if (m_aiShooter)
         {
             m_aiShooter.ToggleGunAndHandRenderers(false, "ExpandParasiteBossPortalBehavior");
         }
         if (hasOutlinesDuringAnim)
         {
             SpriteOutlineManager.ToggleOutlineRenderers(m_aiActor.sprite, true);
         }
     }
     else if (state == TeleportState.PostTeleport)
     {
         m_aiAnimator.PlayUntilFinished(portalAnim, true, null, -1f, false);
         if (m_portalController)
         {
             m_portalController.targetRadius = PortalSize;
         }
     }
 }