public Trajectory InitMovement(Vector3 origin, Vector3 target, Vector3 next, bool end) { Quaternion to = Quaternion.identity; Quaternion from = Quaternion.identity; if (end) { to = Quaternion.LookRotation(origin - target); from = to; } else { to = Quaternion.LookRotation(next - target); // set "to" rotation to look at the next point from = Quaternion.LookRotation(origin - target); // set "from" rotation to look at the previous point } // Set target rotation pair targetRot = new RotationPair(target, from, to, end); // Set origin rotation pair to = Quaternion.LookRotation(target - origin); from = to; originRot = new RotationPair(origin, from, to, false); return(new Trajectory(radius, origin, target, Quaternion.LookRotation(prevPosition - originRot.Pivot), to, targetRot.From, targetRot.To, targetRot.EndPoint )); }
bool OnApproachTarget(Vector3 ghostPosition) { float distance = Vector3.Distance(ghostPosition, targetRot.Pivot); if (distance > radius) { return(false); } proximity = (distance / radius).Map(1f, 0f, 0f, 0.5f); nearest = targetRot; prevPosition = targetRot.FromPosition; return(true); }
bool OnDepartOrigin(Vector3 ghostPosition, int pathPosition) { float distance = Vector3.Distance(ghostPosition, originRot.Pivot); if (distance > radius) { return(false); } proximity = distance / radius; if (pathPosition > 0) { proximity = proximity.Map(0f, 1f, 0.5f, 1f); } nearest = originRot; return(true); }
public void InitMovement(Vector3 origin, Vector3 target, Vector3 next) { Quaternion to = Quaternion.identity; Quaternion from = Quaternion.identity; if (next != target) { to = Quaternion.LookRotation(next - target); // set "to" rotation to look at the next point from = Quaternion.LookRotation(origin - target); // set "from" rotation to look at the previous point } else if (origin != target) { to = Quaternion.LookRotation(origin - target); from = to; } targetRot = new RotationPair(target, from, to, (origin != target && next == target)); to = Quaternion.LookRotation(target - origin); from = to; originRot = new RotationPair(origin, from, to, false); }