Example #1
0
    private void PlaceBombOnPerformed(InputAction.CallbackContext context)
    {
        Vector2 bombPosition = new Vector2();
        var     position     = _playerBody.position;

        if (_lookDirection.x < 0f)
        {
            bombPosition.Set(position.x - 0.03f, position.y);
            GameObject bombObject = Instantiate(bomb, bombPosition, Quaternion.identity);
        }

        if (_lookDirection.x > 0f)
        {
            bombPosition.Set(position.x + 0.03f, position.y);
            GameObject bombObject = Instantiate(bomb, bombPosition, Quaternion.identity);
        }

        if (_lookDirection.y < 0f)
        {
            bombPosition.Set(position.x, position.y - 0.8f);
            GameObject bombObject = Instantiate(bomb, bombPosition, Quaternion.identity);
        }

        if (_lookDirection.y > 0f)
        {
            bombPosition.Set(position.x, position.y + 0.8f);
            GameObject bombObject = Instantiate(bomb, bombPosition, Quaternion.identity);
        }
    }
        void Update()
        {
            //Must be the local player, or they cannot move
            if (!isLocalPlayer)
            {
                return;
            }

            //Ignore movement controls when typing in chat
            if (chatRegister.ChatWindow != null && chatRegister.ChatWindow.PlayerIsTyping())
            {
                currentMovement.Set(0, 0);
                return;
            }

            if (Input.GetButtonDown("Toggle Run"))
            {
                isWalking = !isWalking;
            }

            // TODO: Implement gravity and grabbing
            // Calculate next movement
            // The vector is not normalized to allow for the input having potential rise and fall times
            float x = Input.GetAxisRaw("Horizontal");
            float y = Input.GetAxisRaw("Vertical");

            // Smoothly transition to next intended movement
            intendedMovement = new Vector2(x, y).normalized *(isWalking ? walkSpeed : runSpeed);
            currentMovement  = Vector2.MoveTowards(currentMovement, intendedMovement, Time.deltaTime * (Mathf.Pow(ACCELERATION / 5f, 3) / 5));

            absoluteMovement = new Vector3(absoluteMovement.x, 0, absoluteMovement.z);
            // Move the player
            if (currentMovement != Vector2.zero)
            {
                // Determine the absolute movement by aligning input to the camera's looking direction
                Vector3 absoluteMovement =
                    currentMovement.y * Vector3.Cross(mainCamera.transform.right, Vector3.up).normalized +
                    currentMovement.x * Vector3.Cross(Vector3.up, mainCamera.transform.forward).normalized;

                if (intendedMovement != Vector2.zero)
                {
                    // Move (without gravity). Whenever we move we also readjust the player's direction to the direction they are running in.
                    characterController.Move(absoluteMovement * (Time.deltaTime / 3.5f));

                    transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(absoluteMovement), Time.deltaTime * 10);
                }
                if (intendedMovement == Vector2.zero)
                {
                    absoluteMovement = Vector3.Lerp(absoluteMovement, Vector3.zero, Time.deltaTime * 5);
                }
                characterController.Move(absoluteMovement * Time.deltaTime);
            }
            // animation Speed is a proportion of maximum runSpeed, and we smoothly transitions the speed with the Lerp
            float currentSpeed = characterAnimator.GetFloat("Speed");
            float newSpeed     = Mathf.LerpUnclamped(currentSpeed, currentMovement.magnitude / runSpeed, Time.deltaTime * (isWalking ? walkSpeed : runSpeed) * 3);

            characterAnimator.SetFloat("Speed", newSpeed);

            ForceHeightLevel();
        }
    //knockback state

    /*
     * enemy knockbacks in side oposite to damage direction
     */
    private void EnterKnockbackState()
    {
        knockbackStartTime = Time.time;
        movement.Set(knockbackSpeed.x * damageDirection, knockbackSpeed.y);
        aliveRigitbody.velocity = movement;
        aliveAnimator.SetBool("knockback", true);
    }
Example #4
0
    private void MoveOnPerformed(InputAction.CallbackContext context)
    {
        var move       = context.ReadValue <Vector2>();
        var horizontal = move.x;
        var vertical   = move.y;

        _lookDirection.Set(horizontal, vertical);


        _playerBody.velocity = new Vector2(horizontal * speed * Time.fixedDeltaTime * 100f, vertical * speed * Time.fixedDeltaTime * 100f);
    }
Example #5
0
 public static Vector2 GetEdgePosition(Socket socket, Vector2 position)
 {
     float width = 0;
     if (socket.Direction == SocketDirection.Output)
     {
         width = BonConfig.SocketSize;
     }
     position.Set(
         socket.X + width,
         socket.Y + (BonConfig.SocketSize/2f));
     return position;
 }
Example #6
0
    static bool Vector2_Set__Single__Single(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 2)
        {
            System.Single       arg0    = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
            System.Single       arg1    = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
            UnityEngine.Vector2 argThis = (UnityEngine.Vector2)vc.csObj;        argThis.Set(arg0, arg1);
            JSMgr.changeJSObj(vc.jsObjID, argThis);
        }

        return(true);
    }
Example #7
0
 static public int Set(IntPtr l)
 {
     try{
         UnityEngine.Vector2 self = (UnityEngine.Vector2)checkSelf(l);
         System.Single       a1;
         checkType(l, 2, out a1);
         System.Single a2;
         checkType(l, 3, out a2);
         self.Set(a1, a2);
         setBack(l, self);
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Example #8
0
    private void Move(float horizontalSpeed, float verticalSpeed)
    {
        _horizontalSpeed = horizontalSpeed;
        _verticalSpeed   = verticalSpeed;

        var move = new Vector2(_horizontalSpeed, _verticalSpeed);

        if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f))
        {
            _lookDirection.Set(move.x, move.y);
            _lookDirection.Normalize();
        }

        _animator.SetFloat(AnimationPropertyLookX, _lookDirection.x);
        _animator.SetFloat(AnimationPropertyLookY, _lookDirection.y);
        _animator.SetFloat(AnimationPropertySpeed, move.magnitude);
    }
Example #9
0
 static int Set(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         UnityEngine.Vector2 obj = (UnityEngine.Vector2)ToLua.CheckObject(L, 1, typeof(UnityEngine.Vector2));
         float arg0 = (float)LuaDLL.luaL_checknumber(L, 2);
         float arg1 = (float)LuaDLL.luaL_checknumber(L, 3);
         obj.Set(arg0, arg1);
         ToLua.SetBack(L, 1, obj);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #10
0
        public void Draw()
        {
            if (Input != null && Output != null)
            {
                _tmpStartPos = GetEdgePosition(Output, _tmpStartPos);
                _tmpEndPos = GetEdgePosition(Input, _tmpEndPos);
                _tmpTangent01 = GetTangentPosition(Output, _tmpStartPos);
                _tmpTangent02 = GetTangentPosition(Input, _tmpEndPos);
                DrawEdge(_tmpStartPos, _tmpTangent01, _tmpEndPos, _tmpTangent02, Output.Type);

                Handles.color = Color.black;
                _tmpStartPos.Set(_tmpEndPos.x - 5, _tmpEndPos.y - 5);
                Handles.DrawLine(_tmpEndPos, _tmpStartPos);
                _tmpStartPos.Set(_tmpEndPos.x - 5, _tmpEndPos.y + 5);
                Handles.DrawLine(_tmpEndPos, _tmpStartPos);
            }
        }
        void FixedUpdate()
        {
            ForceHeightLevel();

            //Must be the local player, or they cannot move
            if (!isLocalPlayer)
            {
                return;
            }

            //Ignore movement controls when typing in chat
            if (chatRegister.ChatWindow != null && chatRegister.ChatWindow.PlayerIsTyping())
            {
                currentMovement.Set(0, 0);
                return;
            }

            if (Input.GetButtonDown("Toggle Run"))
            {
                isWalking = !isWalking;
            }

            // TODO: Implement gravity and grabbing
            // Calculate next movement
            // The vector is not normalized to allow for the input having potential rise and fall times
            float x = Input.GetAxisRaw("Horizontal");
            float y = Input.GetAxisRaw("Vertical");

            // Smoothly transition to next intended movement
            intendedMovement = new Vector2(x, y).normalized *(isWalking ? walkSpeed : runSpeed);
            currentMovement  = Vector2.Lerp(currentMovement, intendedMovement, Time.deltaTime * (Mathf.Pow(ACCELERATION / 9.5f, 3) / 6));

            // Move (without gravity). Whenever we move we also readjust the player's direction to the direction they are running in.
            characterController.Move(absoluteMovement * Time.deltaTime);

            // Move the player
            if (currentMovement != Vector2.zero)
            {
                // Determine the absolute movement by aligning input to the camera's looking direction
                Vector3 absoluteMovement =
                    currentMovement.y * Vector3.Cross(mainCamera.transform.right, Vector3.up).normalized +
                    currentMovement.x * Vector3.Cross(Vector3.up, mainCamera.transform.forward).normalized;

                if (intendedMovement != Vector2.zero)
                {
                    //absoluteMovement = Vector3.Lerp(absoluteMovement, newAbsoluteMovement, Time.deltaTime * 2);
                    // Move (without gravity). Whenever we move we also readjust the player's direction to the direction they are running in.
                    characterController.Move(absoluteMovement * Time.deltaTime);

                    // avoid unwanted rotation when you rotate the camera but isn't doing movement input, comment the "if" to see it

                    // Rotate the chest and head IKs objects
                    Quaternion newChestIKRotation = Quaternion.Lerp(chestIK.rotation, Quaternion.LookRotation(absoluteMovement), Time.deltaTime * (isWalking ? 3 : 10));
                    Quaternion newHeadIKRotation  = Quaternion.Lerp(headIK.rotation, Quaternion.LookRotation(absoluteMovement), Time.deltaTime * (isWalking ? 15 : 5));

                    //float rotationDiference = Quaternion.
                    transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(absoluteMovement), Time.deltaTime * (isWalking ? 5 : 7));
                    //Mathf.Pow(intendedMovement.magnitude, 2)

                    chestIK.rotation = newChestIKRotation;
                    headIK.rotation  = newHeadIKRotation;
                }
                if (intendedMovement == Vector2.zero)
                {
                    Quaternion newChestIKRotation = Quaternion.Lerp(chestIK.rotation, transform.rotation, Time.deltaTime * 3);
                    Quaternion newHeadIKRotation  = Quaternion.Lerp(headIK.rotation, transform.rotation, Time.deltaTime * 8);

                    absoluteMovement = Vector3.Lerp(absoluteMovement, Vector3.zero, Time.deltaTime * 5);
                    characterController.Move(absoluteMovement * Time.deltaTime);

                    chestIK.rotation = newChestIKRotation;
                    headIK.rotation  = newHeadIKRotation;
                }
            }
        }
Example #12
0
 /// <summary>
 /// Calculates the amount of recoil at a given point in a burst
 /// </summary>
 private Vector2 GetRecoilVec()
 {
     Vector2 recoilVec = new Vector2(0, 0);
     if (this.cpCustomGet != null)
     {
         Vector2 recoilOffsetX = this.cpCustomGet.recoilOffsetX;
         Vector2 recoilOffsetY = this.cpCustomGet.recoilOffsetY;
         if (!(recoilOffsetX.Equals(Vector2.zero) && recoilOffsetY.Equals(Vector2.zero)))
         {
             int currentBurst = Math.Min(this.verbProps.burstShotCount - this.burstShotsLeft, 20);
             recoilVec.Set(UnityEngine.Random.Range(recoilOffsetX.x, recoilOffsetX.y), UnityEngine.Random.Range(recoilOffsetY.x, recoilOffsetY.y));
             recoilVec *= (float)Math.Sqrt((1 - shootingAccuracy) * currentBurst);
         }
     }
     return recoilVec;
 }
Example #13
0
 /// <summary>Projects the assigned position to a node relative position.</summary>
 /// <param name="canvasPosition">The position in canvas coordinates.</param>
 /// <returns>The position in node coordinates</returns>
 public Vector2 ProjectToNode(Vector2 canvasPosition)
 {
     canvasPosition.Set(canvasPosition.x - WindowRect.x, canvasPosition.y - WindowRect.y);
     return canvasPosition;
 }
Example #14
0
		/// <summary>
		/// UV値を考慮した、テクスチャのアルファ値に依る透過確認
		/// </summary>
		/// <returns>透過か(true:透過, false:不透明)</returns>
		/// <param name="texture">テクスチャ</param>
		/// <param name="uv1">三角形頂点のUV値</param>
		/// <param name="uv2">三角形頂点のUV値</param>
		/// <param name="uv3">三角形頂点のUV値</param>
		/// <remarks>
		/// 理想ならば全テクセルを確認しなければならないが、
		/// 現在の実装では三角形を構成する各頂点のUV・重心・各辺の中心点の7点のテクセルしか確認していない
		/// </remarks>
		static bool IsTransparentByTextureAlphaWithUv(Texture2D texture, Vector2 uv1, Vector2 uv2, Vector2 uv3)
		{
			bool result = true; //透過
			do {
				//座標系が相違しているので補正
				uv1.Set(uv1.x, 1.0f - uv1.y - (1.0f / texture.height));
				uv2.Set(uv2.x, 1.0f - uv2.y - (1.0f / texture.height));
				uv3.Set(uv3.x, 1.0f - uv3.y - (1.0f / texture.height));
				
				const float c_threshold = 253.0f / 255.0f; //253程度迄は不透明として見逃す

				//頂点直下
				if (texture.GetPixelBilinear(uv1.x, uv1.y).a < c_threshold) {
					break;
				}
				if (texture.GetPixelBilinear(uv2.x, uv2.y).a < c_threshold) {
					break;
				}
				if (texture.GetPixelBilinear(uv3.x, uv3.y).a < c_threshold) {
					break;
				}

				//重心
				Vector2 center = new Vector2((uv1.x + uv2.x + uv3.x) / 3.0f, (uv1.y + uv2.y + uv3.y) / 3.0f);
				if (texture.GetPixelBilinear(center.x, center.y).a < c_threshold) {
					break;
				}

				//辺中央
				Vector2 uv12 = new Vector2((uv1.x + uv2.x) / 2.0f, (uv1.y + uv2.y) / 2.0f);
				if (texture.GetPixelBilinear(uv12.x, uv12.y).a < c_threshold) {
					break;
				}
				Vector2 uv23 = new Vector2((uv2.x + uv3.x) / 2.0f, (uv2.y + uv3.y) / 2.0f);
				if (texture.GetPixelBilinear(uv23.x, uv23.y).a < c_threshold) {
					break;
				}
				Vector2 uv31 = new Vector2((uv3.x + uv1.x) / 2.0f, (uv3.y + uv1.y) / 2.0f);
				if (texture.GetPixelBilinear(uv31.x, uv31.y).a < c_threshold) {
					break;
				}

				//此処迄来たら不透明
				result = false;
			} while(false);
			return result;
		}
Example #15
0
        //-----------------------------------------------------
        public override Vector2 GetCursorPos()
        {
            if(m_cPosTime != Time.time)
            {
            m_cPosTime = Time.time;
            m_cPos.Set(0f, 0f);

            if(Input.touchCount > 0)
            {
                foreach(Touch t in Input.touches)
                {
                    m_cPos.x += t.position.x;
                    m_cPos.y += t.position.y;
                }

                m_cPos /= Input.touches.Length;
                m_cPos.Set( m_cPos.x < 0.0f ? Mathf.Ceil(m_cPos.x-0.5f) : Mathf.Floor(m_cPos.x+0.5f),
                            m_cPos.y < 0.0f ? Mathf.Ceil(m_cPos.y-0.5f) : Mathf.Floor(m_cPos.y+0.5f));

                m_oldCpos.Set(m_cPos.x, m_cPos.y);
                // Note : on n'utilise pas Mathf.Round car en cas de *.5, il retourne le l'entier pair le plus proche
                // au lieu de l'entier supérieur.
            }
            else
                m_cPos.Set(m_oldCpos.x, m_oldCpos.y);
            }
            return m_cPos;
        }
Example #16
0
 public static Vector2 Round(this Vector2 vec, int decimals)
 {
     vec.Set((float)Math.Round(vec.x, decimals),
             (float)Math.Round(vec.y, decimals));
     return(vec);
 }