コード例 #1
0
        private void OnCollisionEnter2D(Collision2D collision)
        {
            switch (collisionBehaviour)
            {
            case CollisionBehaviour.None:
                return;

            case CollisionBehaviour.Rebound:
                var reflectedPosition = Vector2.Reflect(transform.right, collision.contacts[0].normal);
                rigidbody.velocity = reflectedPosition.normalized * thrust;
                Vector3 direction = rigidbody.velocity;
                float   angle     = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
                rigidbody.freezeRotation = false;
                rigidbody.MoveRotation(angle);
                rigidbody.angularVelocity = 0f;
                break;

            case CollisionBehaviour.Fall:
                rigidbody.gravityScale = 9.81f;
                aerialMovementState    = AerialMovementState.Stop;
                break;

            case CollisionBehaviour.Explode:
                Destroy(gameObject);     ///TODO: Add Explode effect/particles + change this with object pooling
                break;

            case CollisionBehaviour.Disappear:
                Destroy(gameObject);     ///TODO: Change this with object pooling
                break;
            }
        }
コード例 #2
0
        private IEnumerator ArriveAtWaypoint(float delay = 2f)
        {
            aerialMovementState = AerialMovementState.Stop;
            yield return(new WaitForSeconds(delay));

            if (++waypointIndex > waypoints.Length - 1)
            {
                waypointIndex = 0;
            }
            currentWaypoint     = waypoints[waypointIndex];
            aerialMovementState = AerialMovementState.Patrol;
        }
コード例 #3
0
        void OnJumpTriggered()
        {
            animator.SetFloat(hashVerticalSpeed, 1.0f);

            aerialState   = AerialMovementState.Jumping;
            fallDirection = CalculateLocalInputDirection();

            if (IsIdleForwardJump())
            {
                switch (movementMode)
                {
                case MotorMovementMode.Exploration:
                    NForwardSpeed = 1f;
                    break;

                case MotorMovementMode.Strafe:
                    NLateralSpeed = input.Axis.x;
                    NForwardSpeed = input.Axis.y;
                    break;
                }
            }
        }