当前位置: 首页>>代码示例>>C#>>正文


C# Vector3.toVector2XZ方法代码示例

本文整理汇总了C#中Vector3.toVector2XZ方法的典型用法代码示例。如果您正苦于以下问题:C# Vector3.toVector2XZ方法的具体用法?C# Vector3.toVector2XZ怎么用?C# Vector3.toVector2XZ使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector3的用法示例。


在下文中一共展示了Vector3.toVector2XZ方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: attack

 public override void attack(Vector3 target)
 {
     Vector3 p = transform.position;
     p.y = 0.5f + transform.position.y;
     Vector3 v = (target.toVector2XZ() - p.toVector2XZ())
         .toVector3XZ().normalized * bulletSpeed;
     StartCoroutine(attackCoroutine(p, v));
 }
开发者ID:rpfypust,项目名称:RealisticPerspective,代码行数:8,代码来源:Slime.cs

示例2: chase

 public override void chase(Vector3 destination)
 {
     Vector2 direction = destination.toVector2XZ() - transform.position.toVector2XZ();
     if (direction.magnitude > attackRange) {
         Vector3 des = (direction.normalized * attackRange).toVector3XZ() + transform.position;
         agent.SetDestination(des);
     } else
         agent.SetDestination(transform.position);
 }
开发者ID:rpfypust,项目名称:RealisticPerspective,代码行数:9,代码来源:UFO.cs

示例3: attack

    public override void attack(Vector3 target)
    {
        Vector3 position = transform.position;
        position.y = 1f + transform.position.y;
        Vector3 velocity;

        /* We need to find the velocity(direction) which can
         * possibly hit the moving target.
         * Assume the target will keep linear motion with the
         * current predicted velocity, then we have to find
         * the intersection of the target and the bullet being
         * shot.
         * Clearly, a possible hit may happen after t seconds.
         * the velocity of bullet is p / t + v, where
         * p is the position of the target relative to the
         * shooting point,
         * v is the predicted velocity of the target.
         * The motion of the bullet is described as a cone,
         * since we do not know the direction of it.
         * The cone is open along the time axis.
         * The motion of the target is described as a ray.
         * The problem become finding intersection of a cone
         * and a ray.
         * Equation of cone:
         * x^2 + z^2 = (speed^2)(t^2)
         * Equation of ray:
         * (x, t, z) = (p.x + v.x * t, t, p.z + v.z * t)
         * Substitution gives a quadratic equation to solve
         */

        Vector2 p = target.toVector2XZ() - transform.position.toVector2XZ();
        Vector2 v = predictedVelocity.toVector2XZ();
        float a = Vector2.Dot(v, v) - bulletSpeed * bulletSpeed;
        float b = 2.0f * Vector2.Dot(p, v);
        float c = Vector2.Dot(p, p);
        float r1, r2;
        if (Util.solveQuadratic(a, b, c, out r1, out r2) >= 0f
            && (r1 > 0f || r2 > 0f)) {
            float t;
            if (r1 > 0f && r2 > 0f)
                t = Mathf.Min(r1, r2);
            else
                t = Mathf.Max(r1, r2);
            Vector2 u = p / t + v;
            velocity = u.toVector3XZ().normalized * bulletSpeed;
        } else {
            velocity = p.toVector3XZ().normalized * bulletSpeed;
        }
        UniformMotion um = BulletFactory.CreateUniformMotionBullet(position, velocity, bulletLife);
        um.startMoving();
    }
开发者ID:rpfypust,项目名称:RealisticPerspective,代码行数:51,代码来源:Turret.cs

示例4: chase

 public virtual void chase(Vector3 destination)
 {
     Vector2 direction = destination.toVector2XZ() - transform.position.toVector2XZ();
     if (direction.magnitude > attackRange) {
         Vector3 des = (direction.normalized * attackRange).toVector3XZ() + transform.position;
         agent.SetDestination(des);
     } else {
         agent.SetDestination(transform.position);
         Quaternion targetRotation = Quaternion.LookRotation(direction.toVector3XZ());
         Quaternion newRotation = Quaternion.Lerp(transform.rotation,
                                                  targetRotation,
                                                  agent.angularSpeed * Time.deltaTime);
         transform.rotation = newRotation;
     }
 }
开发者ID:rpfypust,项目名称:RealisticPerspective,代码行数:15,代码来源:Monster.cs

示例5: queryNewPosition

 public Vector3 queryNewPosition(Vector3 p3, MechBlock.Direction d)
 {
     Vector2 p2 = fromWorldToGrid(p3.toVector2XZ());
     int row = (int) p2.x;
     int col = (int) p2.y;
     switch (d) {
     case MechBlock.Direction.EAST:
         p2 = grid.moveBlock(row, col, MechGrid.Direction.DOWN);
         break;
     case MechBlock.Direction.NORTH:
         p2 = grid.moveBlock(row, col, MechGrid.Direction.RIGHT);
         break;
     case MechBlock.Direction.SOUTH:
         p2 = grid.moveBlock(row, col, MechGrid.Direction.LEFT);
         break;
     case MechBlock.Direction.WEST:
         p2 = grid.moveBlock(row, col, MechGrid.Direction.UP);
         break;
     }
     p2 = fromGridtoWorld(p2);
     return p2.toVector3XZ();
 }
开发者ID:rpfypust,项目名称:RealisticPerspective,代码行数:22,代码来源:MechStageMechanics.cs

示例6: canLaunchAttack

 public bool canLaunchAttack(Vector3 destination)
 {
     float distance = (destination.toVector2XZ() - transform.position.toVector2XZ()).magnitude;
     return (distance <= attackRange && attackIntervalTimer >= attackInterval);
 }
开发者ID:rpfypust,项目名称:RealisticPerspective,代码行数:5,代码来源:Monster.cs

示例7: attack

 public override void attack(Vector3 target)
 {
     Vector2 p = transform.position.toVector2XZ();
     Vector2 dir = target.toVector2XZ() - p;
     StartCoroutine(attackCoroutine(dir.normalized));
 }
开发者ID:rpfypust,项目名称:RealisticPerspective,代码行数:6,代码来源:UFO.cs


注:本文中的Vector3.toVector2XZ方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。