示例#1
0
    public void h_5_3()
    {
        GameObject playerShip = GameObject.Find("PlayerGO");

        if (playerShip != null)
        {
            GameObject bullet1 = (GameObject)Instantiate(EnemyBulletGO);
            GameObject bullet2 = (GameObject)Instantiate(EnemyBulletGO);
            GameObject bullet3 = (GameObject)Instantiate(EnemyBulletGO);

            bullet1.transform.position = transform.position;
            bullet2.transform.position = transform.position;
            bullet3.transform.position = transform.position;

            Vector2 direction1 = playerShip.transform.position - bullet1.transform.position;
            Vector2 direction2 = Vector2Extension.Rotate(direction1, 30);
            Vector2 direction3 = Vector2Extension.Rotate(direction1, -30);
            bullet1.GetComponent <EnemyBullet>().SetDirection(direction1);
            bullet2.GetComponent <EnemyBullet>().SetDirection(direction2);
            bullet3.GetComponent <EnemyBullet>().SetDirection(direction3);
        }
        if (numFired < 4)
        {
            Invoke("h_5_3", 0.3f);
            numFired++;
        }
        else
        {
            numFired = 0;
        }
    }
示例#2
0
    private void Start()
    {
        forceVector = Sun.transform.position - transform.position;
        forceVector = Vector2Extension.Rotate(forceVector, 90);

        rb2d.velocity += forceVector.normalized * Mathf.Sqrt(Attractor.G * SunRb2d.mass / Vector2.Distance(Sun.transform.position, transform.position));
    }
示例#3
0
    public virtual void LateUpdate()
    {
        Physics.Raycast(cameraT.position, cameraT.forward, out hit, Mathf.Infinity, layermasknum);
        HandleDamage();
        HandleCooldownTimers();
        attackingPrev = isAttacking;
        charInput.CollectInputs();
        animator.speed = speedMult / Mathf.Pow(Vector2Extension.averageComponentLength(transform.localScale), 0.2f);
        Knockback();
        if (flying)
        {
            fly();
        }
        else
        {
            jump();
            //if(knockback==0){
            move();
            //}else{
            //	KnockbackMove();
            //}
        }
        attack();

        if (gameObject.tag == "Player")
        {
            HandleTimeScale(timeSpeed);
        }


        launchAttack();

        //Debug.DrawRay(transform.position,forceVelVec*100,Color.red);
    }
    // Update is called once per frame
    void Update()
    {
        Transform ikBase          = GetComponent <TentacleAnimation> ().IKBase;
        Transform IKTipOfTentacle = GetComponent <TentacleAnimation> ().IKTipOfTentacle;
        bool      isArm           = IKTipOfTentacle == null && ikBase != null;

        Vector3 mousePos           = c.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 13));
        Vector3 orientation        = ((Vector2)mousePos - (Vector2)this.transform.position).normalized;
        Vector3 targetDistanceVect = center.position + orientation * targetDistance;

        if (isArm)
        {
            // move arm
            Vector2 reference = Vector2.down;
            ikBase.localScale    = Vector2.one * 16f;
            ikBase.localPosition = new Vector3(4, 0, -1);
            if (this.GetComponentInParent <MoveBehaviour> ().facingRight)
            {
                ikBase.localScale    = new Vector2(-16f, 16f);
                ikBase.localPosition = new Vector3(-3.5f, 0, -1);
                // reference = Vector2.up;
            }
            ikBase.rotation = Quaternion.Euler(0, 0, Vector2.SignedAngle(reference, orientation));
        }
        else
        {
            GetComponent <TentacleAnimation> ().IKBase.position = center.position + orientation * 3;
            Vector2 left  = Vector2Extension.Rotate(orientation * targetDistance, 90);
            Vector2 right = Vector2Extension.Rotate(orientation * targetDistance, -90);
            Vector2 pos   = left.y > right.y ? left : right;
            GetComponent <TentacleAnimation> ().IKTipOfTentacle.GetComponent <TargetJoint2D> ().target = (Vector2)targetDistanceVect + pos;
        }
    }
示例#5
0
    public void GenerateHandles(int i)
    {
        //Find a median angle
        float angle = Vector2Extension.SignedAngle(
            (points.Loop(i + 1).position - points[i].position).normalized,
            (points.Loop(i - 1).position - points[i].position).normalized
            );

        if (angle > 0)
        {
            angle = -(360f - angle);
        }
        Vector2 median = ((points.Loop(i + 1).position - points[i].position).normalized).Rotate(angle / 2);

        if (!clockwise)
        {
            median *= -1;
        }
        //Check for sudden angle inversions when clockwise order didn't change
        if (points[i].clockwise == clockwise && Mathf.Abs(Vector2Extension.SignedAngle(points[i].median, median)) > 135)
        {
            median *= -1;
        }
        //Calculate bezier handles
        points[i].handleP = median.Rotate(90 * (clockwise?-1:1)) + points[i].position;
        points[i].handleN = median.Rotate(90 * (clockwise?1:-1)) + points[i].position;
        //Multiply points by half of the distance to neighboring point
        points[i].handleP = ((points[i].handleP - points[i].position) * (Vector2.Distance(points.Loop(i - 1).position, points[i].position) * points[i].curve)) + points[i].position;
        points[i].handleN = ((points[i].handleN - points[i].position) * (Vector2.Distance(points.Loop(i + 1).position, points[i].position) * points[i].curve)) + points[i].position;
        //Store the cofiguration
        points[i].median    = median;
        points[i].clockwise = clockwise;
    }
示例#6
0
    public bool IsValidGridPosition(Transform obj)
    {
        Vector2 v = Vector2Extension.roundVec2(obj.position);

        if (!InsideBorder(v))
        {
            return(false);
        }

        if (gameGridcol[(int)v.x].row[(int)v.y] != null)
        {
            if (obj.gameObject.tag.Equals("Snake"))
            {
                if (gameGridcol[(int)v.x].row[(int)v.y].gameObject.tag.Equals("Food"))
                {
                    Managers.Audio.PlayEatSound();
                    Managers.Game.snake.AddTail();
                    Managers.Score.OnScore(1);
                    Destroy(gameGridcol[(int)v.x].row[(int)v.y].gameObject);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }

        return(true);
    }
示例#7
0
    public void UpdateGrid(Transform obj)
    {
        for (int y = 0; y < 27; ++y)
        {
            for (int x = 0; x < 49; ++x)
            {
                if (gameGridcol[x].row[y] != null)
                {
                    gameGridcol[x].row[y] = null;
                }
            }
        }

        foreach (Transform child in Managers.Game.snakeHolder)
        {
            Vector2 v = Vector2Extension.roundVec2(child.position);
            gameGridcol[(int)v.x].row[(int)v.y] = child;
        }

        foreach (Transform child in Managers.Game.foodHolder)
        {
            Vector2 v = Vector2Extension.roundVec2(child.position);
            gameGridcol[(int)v.x].row[(int)v.y] = child;
        }
    }
示例#8
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("NPC") || other.CompareTag("Player") || other.CompareTag("Ragdoll"))
        {
            float angle = Vector2Extension.DirectionAngle(other.transform.position - transform.position);

            if (angle > 180 && angle < 270)
            {
                float amountOver = angle - 180;
                angle -= 2 * amountOver;
            }
            else if (angle >= 270)
            {
                float amountUnder360 = 360 - angle;
                angle = amountUnder360;
            }

            if (other.CompareTag("Ragdoll"))
            {
                DixieRagdoll ragdoll = other.GetComponent <DixieRagdoll>();
                if (ragdoll != null)
                {
                    ragdoll.SetForceDirection(power, angle);
                }
            }
            else
            {
                HealthSystem healthSystem = other.GetComponent <HealthSystem>();


                healthSystem.TakeDamage(25, angle);
            }
        }
    }
示例#9
0
        public void UpdateGrid(Transform obj)
        {
            for (int y = 0; y < 20; y++)
            {
                for (int x = 0; x < 10; x++)
                {
                    if (gameGridcol[x].row[y] != null)
                    {
                        if (gameGridcol[x].row[y].parent == obj)
                        {
                            gameGridcol[x].row[y] = null;
                        }
                    }
                }
            }

            foreach (Transform child in obj)
            {
                if (child.gameObject.tag.Equals("Block"))
                {
                    Vector2 v = Vector2Extension.roundVec2(child.position);
                    gameGridcol[(int)v.x].row[(int)v.y] = child;
                }
            }
        }
示例#10
0
    private void PlayerMovementUpdate()
    {
        currentPlayerMovementImpulse += movementInpulseIncreaseSpeed * Time.deltaTime;

        if (isActivePlayerCharacter)
        {
            Vector2 mousePointingDirection = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
            Debug.DrawRay(transform.position, mousePointingDirection.normalized);

            float mouseAngle = Mathf.Clamp(Vector2.SignedAngle(playerMovementForwardDirection, mousePointingDirection), -90f, 90f);
            //Debug.LogFormat("Mouse angle = {0}", mouseAngle);
            float turnAngleImpulseRatio = Mathf.Abs(mouseAngle / 90f);

            Vector2 turnForceDirection = Vector2Extension.Rotate(playerMovementForwardDirection, mouseAngle);

            Debug.DrawRay(transform.position, turnForceDirection.normalized * currentPlayerMovementImpulse * Time.deltaTime, Color.red);

            playerRigidBody.AddForce(turnForceDirection.normalized * turnAngleImpulseRatio * currentPlayerMovementImpulse * Time.deltaTime);
            playerMovementForwardDirection = playerRigidBody.velocity.normalized;
            Debug.DrawRay(transform.position, playerMovementForwardDirection);

            float leftOverForwardImpulse = currentPlayerMovementImpulse * (1 - turnAngleImpulseRatio);

            playerRigidBody.AddForce(playerMovementForwardDirection.normalized * leftOverForwardImpulse * currentPlayerMovementImpulse * Time.deltaTime);
            Debug.DrawRay(transform.position, playerMovementForwardDirection.normalized * leftOverForwardImpulse * currentPlayerMovementImpulse * Time.deltaTime, Color.green);
        }
        else
        {
            playerRigidBody.AddForce(playerMovementForwardDirection.normalized * currentPlayerMovementImpulse * Time.deltaTime);
            Debug.DrawRay(transform.position, playerMovementForwardDirection.normalized * currentPlayerMovementImpulse * Time.deltaTime, Color.green);
        }
    }
示例#11
0
    public bool IsValidGridPosition(Transform obj)
    {
        foreach (Transform child in obj)
        {
            if (child.gameObject.tag.Equals("Block"))
            {
                Vector2 v = Vector2Extension.roundVec2(child.position);

                if (!InsideBorder(v))
                {
                    return(false);
                }

                if (gameGridcol[(int)v.x].row[(int)v.y] != null && !gameGridcol[(int)v.x].row[(int)v.y].gameObject.activeInHierarchy)
                {
                    return(false);
                }

                // Block in grid cell (and not part of same group)?
                if (gameGridcol[(int)v.x].row[(int)v.y] != null &&
                    gameGridcol[(int)v.x].row[(int)v.y].parent != obj)
                {
                    return(false);
                }
            }
        }
        return(true);
    }
示例#12
0
    void LateUpdate()
    {
        _direction = Vector2Extension.RotateTowards(_direction, _targetDirection, 2f).normalized;
        // _direction = Vector3.RotateTowards(_direction, _targetDirection, 0.1f, 0).normalized;

        _transform.position += (_unit.GetShipSpeed() * Time.deltaTime) * _direction * 2;
        float angle = Mathf.Atan2(_direction.y, _direction.x) * Mathf.Rad2Deg - 90f;

        _transform.eulerAngles = new Vector3(0, 0, angle);
    }
示例#13
0
    /// <summary>
    /// Draws debug information using gizmos.
    /// </summary>
    protected virtual void OnDrawGizmos()
    {
        Vector2 ray = transform.right * sensorRadius;

        Gizmos.color = Color.yellow;
        Gizmos.DrawWireSphere(transform.position, sensorRadius);
        Gizmos.color = Color.magenta;
        Gizmos.DrawRay(transform.position, Vector2Extension.Rotate(ray, -sensorAngle));
        Gizmos.DrawRay(transform.position, Vector2Extension.Rotate(ray, sensorAngle));
    }
示例#14
0
        public void DeployAttack(SpecialAttack attack)
        {
            var direction = Vector2Extension.AngleToVector2(Rotation);

            attack.Position = Position + direction * Size / 2;

            attack.ApplyForce(direction * attack.MaxSpeed, instantaneous: true);
            ApplyForce(-direction * attack.Mass, instantaneous: true);

            Level.AddEntity(attack);
        }
    Vector2 rotate_transform_robot(Vector2 curr_dir, float angle_deg)
    {
        Vector2 cur_dir_result;

        _rigidbody2D.MoveRotation(_rigidbody2D.rotation + angle_deg);

        cur_dir_result = Vector2Extension.Rotate(curr_dir, angle_deg);

        if (_rigidbody2D.rotation > 360.0f || _rigidbody2D.rotation < -360.0f)
        {
            _rigidbody2D.SetRotation(_rigidbody2D.rotation % 360.0f);
        }

        return(cur_dir_result);
    }
示例#16
0
    public bool IsValidGridPosition(Transform obj)
    {
        foreach (Transform child in obj)
        {
            if (child.gameObject.tag.Equals("Block"))
            {
                Vector2 v = Vector2Extension.roundVec2(child.position);

                bool insideX = InsideBorderX(v);
                bool insideY = InsideBorderY(v);

                if (!insideX)
                {
                    Debug.Log("Block hit side.");
                    return(false);
                }

                if (!insideY)
                {
                    Debug.Log("Block hit bottom.");
                    PostLandingChores(obj.gameObject);
                    return(false);
                }
                //if (!InsideBorderX(v))
                //{
                //    if (obj.transform.position.y != -1)
                //    {
                //        Debug.Log("Block hit side.");
                //        return false;
                //    }
                //    Debug.Log("Block hit bottom.");
                //    PostLandingChores(obj.gameObject);
                //    return false;
                //}

                // Block in grid cell (and not part of same group)?
                if (gameGridcol[(int)v.x].row[(int)v.y] != null &&
                    gameGridcol[(int)v.x].row[(int)v.y].parent != obj)
                {
                    Debug.Log("Block hit another block.");
                    PostLandingChores(obj.gameObject);
                    return(false);
                }
            }
        }
        return(true);
    }
示例#17
0
    IEnumerator BeakerBurst(float cooldown)
    {
        if (_beaker != null && _player != null)
        {
            Vector3 targetDirection1 = _playerTrans.position - transform.position;
            Instantiate(_beaker, transform.position, Quaternion.FromToRotation(Vector3.right, targetDirection1));
            if (_health <= _startHealth / 2)
            {
                Debug.Log("Dog phase 2");
                Vector3 targetDirection2 = new Vector3(targetDirection1.x, targetDirection1.y, 0);
                Vector2Extension.Rotate((Vector2)targetDirection2, 15);
                Instantiate(_beaker, transform.position, Quaternion.FromToRotation(Vector3.right, targetDirection2));
            }

            yield return(new WaitForSeconds(cooldown));

            _canAttack = true;
        }
    }
    public FloorNode InstantiateFloorNode(Vector2 u, Vector2 v)
    {
        // get direction/angle
        // get midpoint along vector
        // instantiate nice WalkNodes with dimensions that will stick out the proper amount (height should be 3)

        Vector3 midpoint = new Vector3((u.x + v.x) / 2 + transform.position.x, (u.y + v.y) / 2 + transform.position.y, 0);
        //I'm not sure if this is correct. Assume u is the tail
        float angle = Vector2Extension.DirectionAngle(v - u);

        float width = Vector2.Distance(u, v);

        GameObject floorNodePrefab = Resources.Load("Prefabs/FloorNodePrefab") as GameObject;

        GameObject walkNodeGameObject = Instantiate <GameObject>(floorNodePrefab);

        walkNodeGameObject.transform.SetPositionAndRotation(midpoint, Quaternion.Euler(0, 0, angle));
        walkNodeGameObject.transform.localScale = new Vector3(width, 2, 1);
        return(walkNodeGameObject.AddComponent <FloorNode>());
    }
示例#19
0
        protected override void Destroy()
        {
            hitsCount--;

            if (collisionNormal != Vector3.zero)
            {
                float angle = 2 * Vector3.Angle(direction, collisionNormal) - 180;
                if (Vector3.Cross(direction, collisionNormal).z < 0)
                {
                    angle = -angle;
                }
                direction       = Vector2Extension.Rotate(direction, angle);
                collisionNormal = Vector3.zero;
            }

            if (hitsCount <= 0)
            {
                base.Destroy();
            }
        }
示例#20
0
 public override void CollectInputs()
 {
     inputDir             = Vector2.zero;
     vecToPlayerPrev      = vecToPlayer;
     leftMouseDownPrev    = leftMouseDown;
     leftMouseDown        = false;
     walking              = false;
     switchAttackModePrev = switchAttackMode;
     switchAttackMode     = false;
     vecToPlayer          = playerScript.centerPoint.position - centerPoint.transform.position;
     if (!!!controllerScript.dead)
     {
         cameraT.forward = vecToPlayer;
     }
     if (controllerScript.attackMode && !controllerScript.dead)
     {
         if (controllerScript.hit.distance != 0 && hitLayerIsEnemy(controllerScript.hit.collider.gameObject.layer))
         {
             leftMouseDown = true;
         }
         Debug.DrawRay(centerPoint.transform.position, vecToPlayer * 10000);
         //Vector3 projectedInputDir = Vector3.ProjectOnPlane(vecToPlayer,Vector3.up);
         if (Vector2Extension.XzPlaneMagnitude(vecToPlayer) > minPlayerRadius + 0.5f)
         {
             inputDir = Vector2.up;
         }
         else
         {
             inputDir = Vector2.Lerp(Vector2.down, Vector2.zero, Vector2Extension.XzPlaneMagnitude(vecToPlayer) / minPlayerRadius);
         }
         //Vector2Extension.Rotate(new Vector2(projectedInputDir.x,projectedInputDir.z),cameraT.eulerAngles.y);
     }
     if (Vector2Extension.XzPlaneMagnitude(vecToPlayer) < 0.5 * sightRadius)
     {
         walking = true;
     }
     if (vecToPlayer.magnitude < sightRadius)
     {
         controllerScript.attackMode = true;
     }
 }
示例#21
0
    void UpdateFOVPoints()
    {
        Vector2 direction;

        if ((Vector2)agent.velocity.normalized == Vector2.zero)
        {
            direction = direction_tmp;
        }
        else
        {
            direction     = agent.velocity.normalized;
            direction_tmp = direction;
        }
        Vector2[] points = new Vector2[6];
        points[0] = Vector2.zero;
        points[1] = Vector2Extension.Rotate(direction, (angle) / 2) * range;
        points[2] = Vector2Extension.Rotate(direction, (angle) / 4) * range;
        points[3] = direction * range;
        points[4] = Vector2Extension.Rotate(direction, (-angle) / 4) * range;
        points[5] = Vector2Extension.Rotate(direction, (-angle) / 2) * range;
        polygoncoll.SetPath(0, points);
    }
示例#22
0
        public async Task <bool> FireLaser(CancellationToken cancellation)
        {
            if (MainWeaponAmmo.IsEmpty)
            {
                return(false);
            }

            var direction = Vector2Extension.AngleToVector2(Rotation);

            var laser = new Laser(this, Momentum, Position, direction);

            laser.ApplyAcceleration(direction * laser.MaxSpeed, instantaneous: true);
            ApplyForce(-direction * laser.Mass, instantaneous: true);

            MainWeaponAmmo.Quantity--;
            SoundManager.PlaySound("Shoot01");
            Level.AddEntity(laser);

            await UpdateContext.Delay(MainWeaponDelay);

            return(true);
        }
示例#23
0
        public bool IsValidGridPosition(Transform obj)
        {
            foreach (Transform child in obj)
            {
                if (child.gameObject.tag.Equals("Block"))
                {
                    Vector2 v = Vector2Extension.roundVec2(child.position);
                    if (!InsideBorder(v))
                    {
                        return(false);
                    }

                    if (gameGridcol[(int)v.x].row[(int)v.y] != null &&
                        gameGridcol[(int)v.x].row[(int)v.y].parent != obj)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#24
0
        public void Accelerate(GameTime gameTime, float thrust)
        {
#if DEBUG
            if (Math.Abs(thrust) > 1)
            {
                throw new ArgumentOutOfRangeException("thrust", "Thrust must be between -1 and 1.");
            }
#endif
            _accelerating = 0;
            if (Math.Abs(thrust) < 0.1f)
            {
                return;
            }

            var fuelNeeded = (int)(gameTime.ElapsedGameTime.TotalMilliseconds * Math.Abs(thrust));

            if (Fuel.Quantity > fuelNeeded)
            {
                _accelerating  = thrust;
                Fuel.Quantity -= fuelNeeded;
                ApplyForce(Vector2Extension.AngleToVector2(Rotation) * thrust * ThrotleForce);
            }
        }
示例#25
0
        private void UpdateMovement()
        {
            if (target != null)
            {
                var direction = (target.transform.position - transform.position);

                moveAroundTimer += 0.1;
                if (moveAroundTimer > 40)
                {
                    direction = Vector2Extension.Rotate(target.GetVelocityVector(), 90);
                    if (moveAroundTimer > 60)
                    {
                        moveAroundTimer = 0;
                    }
                }

                if (transform.position.magnitude > 8)
                {
                    direction += -transform.position;
                }

                direction.z  = 0;
                acceleration = (direction).normalized * maxAcceleration / 100;
            }

            speed += 4 * acceleration * Engine.GameLoop.NormalizedDeltaTime;
            speed  = speed.normalized * Mathf.Min(speed.magnitude, maxSpeed);
            transform.localPosition += speed * 4 * Engine.GameLoop.NormalizedDeltaTime;

            float angle = Vector3.Angle(Vector3.up, acceleration);

            if (acceleration.x > 0)
            {
                angle = 360 - angle;
            }
            transform.localRotation = Quaternion.Euler(0, 0, angle);
        }
示例#26
0
 private void UpdateCollider()
 {
     col  = GetComponent <Collider2D>();
     mcol = GetComponent <MeshCollider>();
     if (col != null || mcol != null)
     {
         //Create points for a collider
         cpoints.Clear();
         for (int i = 0; i < points.Count; i++)
         {
             if (points[i].curve > 0f || points.Loop(i + 1).curve > 0f)
             {
                 for (int j = 0; j < curveIterations; j++)
                 {
                     cpoints.Add(new PS2DColliderPoint((Vector2)CalculateBezierPoint(
                                                           (float)j / (float)curveIterations,
                                                           points[i].position,
                                                           points[i].handleN,
                                                           points.Loop(i + 1).handleP,
                                                           points.Loop(i + 1).position
                                                           )));
                     cpoints[cpoints.Count - 1].wPosition = transform.TransformPoint(cpoints[cpoints.Count - 1].position);
                 }
             }
             else
             {
                 cpoints.Add(new PS2DColliderPoint((Vector2)points[i].position));
                 cpoints[cpoints.Count - 1].wPosition = transform.TransformPoint(cpoints[cpoints.Count - 1].position);
             }
         }
         //Create normals and directions for every point
         for (int i = 0; i < cpoints.Count; i++)
         {
             //Setting normal
             cpoints[i].normal = cpoints[i].wPosition - cpoints.Loop(i + 1).wPosition;
             cpoints[i].normal = new Vector2(cpoints[i].normal.y, -cpoints[i].normal.x).normalized;
             if (!clockwise)
             {
                 cpoints[i].normal *= -1;
             }
             //Deciding direction
             cpoints[i].signedAngle = Vector2Extension.SignedAngle(Vector2.up, cpoints[i].normal);
             if (Mathf.Abs(cpoints[i].signedAngle) <= colliderTopAngle / 2)
             {
                 cpoints[i].direction = PS2DDirection.Up;
             }
             else if (cpoints[i].signedAngle > (colliderTopAngle / 2) && cpoints[i].signedAngle < 135)
             {
                 cpoints[i].direction = PS2DDirection.Left;
             }
             else if (cpoints[i].signedAngle <-(colliderTopAngle / 2) && cpoints[i].signedAngle> -135)
             {
                 cpoints[i].direction = PS2DDirection.Right;
             }
             else if (Mathf.Abs(cpoints[i].signedAngle) >= 135)
             {
                 cpoints[i].direction = PS2DDirection.Down;
             }
         }
         //Create array of points for collider
         if (col != null)
         {
             //Polygon collider
             if (col.GetType() == typeof(UnityEngine.PolygonCollider2D))
             {
                 cpointsFinal = new Vector2[cpoints.Count];
                 for (int i = 0; i < cpoints.Count; i++)
                 {
                     cpointsFinal[i] = cpoints[i].position;
                     if (cpoints[i].direction == PS2DDirection.Up || cpoints.Loop(i - 1).direction == PS2DDirection.Up)
                     {
                         cpointsFinal[i] += (Vector2.up * colliderOffsetTop);
                     }
                 }
                 GetComponent <PolygonCollider2D>().points = cpointsFinal;
                 //Full edge collider
             }
             else if (col.GetType() == typeof(UnityEngine.EdgeCollider2D) && colliderType == PS2DColliderType.Edge)
             {
                 cpointsFinal = new Vector2[cpoints.Count];
                 for (int i = 0; i < cpoints.Count; i++)
                 {
                     cpointsFinal[i] = cpoints[i].position;
                     if (cpoints[i].direction == PS2DDirection.Up || cpoints.Loop(i - 1).direction == PS2DDirection.Up)
                     {
                         cpointsFinal[i] += (Vector2.up * colliderOffsetTop);
                     }
                 }
                 GetComponent <EdgeCollider2D>().points = cpointsFinal;
                 //Top edge collider
             }
             else if (col.GetType() == typeof(UnityEngine.EdgeCollider2D) && colliderType == PS2DColliderType.TopEdge)
             {
                 int lowestWPoint = 0;
                 for (int i = 0; i < cpoints.Count; i++)
                 {
                     if (i == 0 || cpoints[i].wPosition.y < cpoints[lowestWPoint].wPosition.y)
                     {
                         lowestWPoint = i;
                     }
                 }
                 int edgeStartPoint = -1;
                 for (int i = lowestWPoint; i < lowestWPoint + cpoints.Count; i++)
                 {
                     if (cpoints.Loop(i).direction == PS2DDirection.Up)
                     {
                         edgeStartPoint = cpoints.LoopID(i);
                         break;
                     }
                 }
                 int edgeEndPoint = -1;
                 for (int i = lowestWPoint; i > lowestWPoint - cpoints.Count; i--)
                 {
                     if (cpoints.Loop(i).direction == PS2DDirection.Up)
                     {
                         edgeEndPoint = cpoints.LoopID(i + 1);
                         break;
                     }
                 }
                 if (edgeStartPoint >= 0 && edgeEndPoint >= 0)
                 {
                     //Find number of collider points
                     int countPoints = 1;
                     for (int i = edgeStartPoint; i != edgeEndPoint; i = cpoints.LoopID(i + 1))
                     {
                         countPoints++;
                     }
                     if (countPoints > 1)
                     {
                         //Create collider points
                         cpointsFinal = new Vector2[countPoints];
                         for (int i = 0; i < countPoints; i++)
                         {
                             cpointsFinal[i] = cpoints.Loop(edgeStartPoint + i).position + (Vector2.up * colliderOffsetTop);
                         }
                         //Set collider points
                         GetComponent <EdgeCollider2D>().enabled = true;
                         GetComponent <EdgeCollider2D>().points  = cpointsFinal;
                     }
                     else
                     {
                         GetComponent <EdgeCollider2D>().enabled = false;
                     }
                 }
                 else
                 {
                     GetComponent <EdgeCollider2D>().enabled = false;
                 }
             }
         }
         if (mcol != null)
         {
             //Create two sets of vertices for the mesh collier
             Vector3[] mVertices = new Vector3[mf.sharedMesh.vertices.Length * 2];
             for (int i = 0; i < mf.sharedMesh.vertices.Length; i++)
             {
                 mVertices[i]    = mf.sharedMesh.vertices[i];
                 mVertices[i].z -= cMeshDepth / 2f;
             }
             for (int i = mf.sharedMesh.vertices.Length; i < mf.sharedMesh.vertices.Length * 2; i++)
             {
                 mVertices[i]    = mf.sharedMesh.vertices[i - mf.sharedMesh.vertices.Length];
                 mVertices[i].z += cMeshDepth / 2f;
             }
             //Create triangles for mesh collider
             int[] mTriangles = new int[mf.sharedMesh.triangles.Length * 2 + ((mf.sharedMesh.vertices.Length * 2) * 3)];
             for (int i = 0; i < mf.sharedMesh.triangles.Length; i++)
             {
                 mTriangles[i] = mf.sharedMesh.triangles[i];
             }
             for (int i = mf.sharedMesh.triangles.Length * 2 - 1; i >= mf.sharedMesh.triangles.Length; i--)
             {
                 mTriangles[(mf.sharedMesh.triangles.Length * 2) + mf.sharedMesh.triangles.Length - 1 - i] = mf.sharedMesh.triangles[i - mf.sharedMesh.triangles.Length] + mf.sharedMesh.vertices.Length;
             }
             //Stich the two sides together
             for (int i = 0; i < mf.sharedMesh.vertices.Length; i++)
             {
                 mTriangles[mf.sharedMesh.triangles.Length * 2 + (i * 6) + 0] = i;
                 mTriangles[mf.sharedMesh.triangles.Length * 2 + (i * 6) + 1] = mf.sharedMesh.vertices.Length + i;
                 mTriangles[mf.sharedMesh.triangles.Length * 2 + (i * 6) + 2] = mf.sharedMesh.vertices.Length + i + 1 - (i == mf.sharedMesh.vertices.Length - 1?mf.sharedMesh.vertices.Length:0);
                 mTriangles[mf.sharedMesh.triangles.Length * 2 + (i * 6) + 3] = i;
                 mTriangles[mf.sharedMesh.triangles.Length * 2 + (i * 6) + 4] = mf.sharedMesh.vertices.Length + i + 1 - (i == mf.sharedMesh.vertices.Length - 1?mf.sharedMesh.vertices.Length:0);
                 mTriangles[mf.sharedMesh.triangles.Length * 2 + (i * 6) + 5] = i + 1 - (i == mf.sharedMesh.vertices.Length - 1?mf.sharedMesh.vertices.Length:0);
             }
             cMesh = new Mesh();
             cMesh.SetVertices(new List <Vector3>(mVertices));
             cMesh.SetTriangles(mTriangles, 0);
             //cMesh.RecalculateBounds();
             //cMesh.RecalculateNormals();
             cMesh.name      = transform.name;
             mcol.sharedMesh = null;
             mcol.sharedMesh = cMesh;
         }
     }
 }
示例#27
0
    public virtual void move()
    {
        //walking
        speedMult = Mathf.SmoothDamp(speedMult, 1, ref speedMultDamp, 15f);
        if (knockback == 0 && !dead)
        {
            Vector2 input = charInput.inputDir;
            inputDir = Vector2.SmoothDamp(inputDir, input.normalized, ref inputSmoothDamp, !controller.isGrounded?turnSmoothTime:turnSmoothTime * 1f * ((currentSpeed < 5?5:currentSpeed) / runSpeed));
            if (inputDir != Vector2.zero || animator.GetInteger("attack") == 2 || attackMode)
            {
                float targetRotation = Mathf.Atan2(inputDir.x * (((attackMode && charInput.inputDir.y < 0)?-1:1)), (attackMode)?Mathf.Abs(inputDir.y):inputDir.y) * Mathf.Rad2Deg + cameraT.eulerAngles.y;
                if ((input.magnitude == 0 && controller.isGrounded && attackMode) || drawPad)
                {
                    targetRotation = cameraT.eulerAngles.y;
                }
                transform.eulerAngles = Vector3.up * Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref turnSmoothVelocity, (controller.isGrounded?turnSmoothTime:turnSmoothTime * 1f * ((currentSpeed < 5?5:currentSpeed) / runSpeed)));
            }
            walking = charInput.walking;


            targetSpeed  = ((walking) ? walkSpeed : runSpeed) * inputDir.magnitude;
            currentSpeed = Mathf.SmoothDamp(currentSpeed, targetSpeed, ref speedSmoothVelocity, controller.isGrounded?speedSmoothTime:5f);
        }

        if (controller.isGrounded)
        {
            moveVec = speedMult * ((((attackMode && !outFly)?(Quaternion.AngleAxis(cameraT.eulerAngles.y, Vector3.up) * new Vector3(inputDir.x, 0, inputDir.y)):transform.forward) * currentSpeed)) + (transform.up * moveVec.y) + forceVelVec / Vector2Extension.averageComponentLength(transform.localScale);
        }

        //movement handling

        accelVec.y = -gravity;
        moveVec   += accelVec * Time.deltaTime;
        if (controller.isGrounded && moveVec.y < -30f)
        {
            moveVec.y = -30f;
        }
        controller.Move((moveVec) * Time.deltaTime);
        forceVelVec = Vector3.Lerp(forceVelVec, Vector3.zero, 5 * Time.deltaTime);
        float animationSpeedPercent = ((!walking) ? currentSpeed / runSpeed : currentSpeed / walkSpeed * .5f);
        float targetMoveMode        = attackMode?1:0;

        moveMode = Mathf.SmoothDamp(moveMode, targetMoveMode, ref moveModeVelocity, 0.1f);
        animator.SetInteger("knockback", knockback);
        animator.SetFloat("moveMode", moveMode);
        animator.SetFloat("movespeed", animationSpeedPercent);
        animator.SetFloat("moveX", inputDir.x * animationSpeedPercent);
        animator.SetFloat("moveY", inputDir.y * animationSpeedPercent);
        //Debug.DrawRay(transform.position+(3*Vector3.up),(new Vector3(moveVec.x,0,moveVec.z))*100, Color.blue);
    }
示例#28
0
文件: ABall.cs 项目: liamwhan/pong
 public void Reset()
 {
     Position  = _startingPosition.Clone();
     Direction = Vector2Extension.RandomStartingVector();
 }