如何拍摄一个圆圈运动的物体
How to shoot an object, which is moving in a circle
所以我有一个物体在圆形路径上移动,敌人在这个圆的中心。我正在尝试找出如何计算子弹的 shotingDirection。 Transform.position 是不够的,因为子弹会在最后已知的物体位置发射,所以我需要 predict/calculate 这样的物体位置,这样子弹就会飞到前面,这样它们就可以击中物体
假设我有这个信息:
Vector3 targetPosition = transform.position;
Vector3 shooterPosition = otherTransform.position;
Vector3 rotationAxis = Vector3.forward; // axis of circle
// in counter-clockwise degrees per second around axis
Vector3 targetAngularVelocity = 90f;
Vector3 circleRadius = 5f; // in world units;
Vector3 projectileVelocity = 5f; // in world units per second;
我想找一个 Vector3 shootDirection
。
计算弹丸与目标路径相交所需的时间,然后使用Quaternion.AngleAxis
and quaternion multiplication将当前方向旋转为预测方向:
// INPUTS
Vector3 targetPosition;
Vector3 shooterPosition;
Vector3 rotationAxis = Vector3.forward; // axis of circle
// in counter-clockwise degrees per second around axis
Vector3 targetAngularVelocity = 90f;
Vector3 circleRadius = 5f; // in world units;
Vector3 projectileVelocity = 5f; // in world units per second;
// CALCULATIONS
float timeToIntersect = circleRadius / projectileVelocity;
float traveledAngle = timeToIntersect * targetAngularVelocity;
float traveledRotation = Quaternion.AngleAxis(traveledAngle, rotationAxis);
Vector3 currentDirectionOfTarget = targetPosition - shooterPosition;
Vector3 futureDirection = traveledRotation * currentDirectionOfTarget;
// shoot in futureDirection
所以我有一个物体在圆形路径上移动,敌人在这个圆的中心。我正在尝试找出如何计算子弹的 shotingDirection。 Transform.position 是不够的,因为子弹会在最后已知的物体位置发射,所以我需要 predict/calculate 这样的物体位置,这样子弹就会飞到前面,这样它们就可以击中物体
假设我有这个信息:
Vector3 targetPosition = transform.position;
Vector3 shooterPosition = otherTransform.position;
Vector3 rotationAxis = Vector3.forward; // axis of circle
// in counter-clockwise degrees per second around axis
Vector3 targetAngularVelocity = 90f;
Vector3 circleRadius = 5f; // in world units;
Vector3 projectileVelocity = 5f; // in world units per second;
我想找一个 Vector3 shootDirection
。
计算弹丸与目标路径相交所需的时间,然后使用Quaternion.AngleAxis
and quaternion multiplication将当前方向旋转为预测方向:
// INPUTS
Vector3 targetPosition;
Vector3 shooterPosition;
Vector3 rotationAxis = Vector3.forward; // axis of circle
// in counter-clockwise degrees per second around axis
Vector3 targetAngularVelocity = 90f;
Vector3 circleRadius = 5f; // in world units;
Vector3 projectileVelocity = 5f; // in world units per second;
// CALCULATIONS
float timeToIntersect = circleRadius / projectileVelocity;
float traveledAngle = timeToIntersect * targetAngularVelocity;
float traveledRotation = Quaternion.AngleAxis(traveledAngle, rotationAxis);
Vector3 currentDirectionOfTarget = targetPosition - shooterPosition;
Vector3 futureDirection = traveledRotation * currentDirectionOfTarget;
// shoot in futureDirection