本文整理汇总了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));
}
示例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);
}
示例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();
}
示例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;
}
}
示例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();
}
示例6: canLaunchAttack
public bool canLaunchAttack(Vector3 destination)
{
float distance = (destination.toVector2XZ() - transform.position.toVector2XZ()).magnitude;
return (distance <= attackRange && attackIntervalTimer >= attackInterval);
}
示例7: attack
public override void attack(Vector3 target)
{
Vector2 p = transform.position.toVector2XZ();
Vector2 dir = target.toVector2XZ() - p;
StartCoroutine(attackCoroutine(dir.normalized));
}