added buffer in agv
This commit is contained in:
@@ -12,6 +12,7 @@ interface PathNavigatorProps {
|
||||
id: string;
|
||||
speed: number;
|
||||
bufferTime: number;
|
||||
hitCount: number;
|
||||
}
|
||||
|
||||
export default function PathNavigator({
|
||||
@@ -20,6 +21,7 @@ export default function PathNavigator({
|
||||
id,
|
||||
speed,
|
||||
bufferTime,
|
||||
hitCount,
|
||||
}: PathNavigatorProps) {
|
||||
const [path, setPath] = useState<[number, number, number][]>([]);
|
||||
const progressRef = useRef(0);
|
||||
@@ -32,7 +34,7 @@ export default function PathNavigator({
|
||||
const [startPoint, setStartPoint] = useState(new THREE.Vector3());
|
||||
const isWaiting = useRef<boolean>(false); // Flag to track waiting state
|
||||
const delayTime = bufferTime;
|
||||
|
||||
|
||||
const movingForward = useRef<boolean>(true); // Tracks whether the object is moving forward
|
||||
// Compute distances and total distance when the path changes
|
||||
useEffect(() => {
|
||||
@@ -52,6 +54,7 @@ export default function PathNavigator({
|
||||
progressRef.current = 0;
|
||||
}, [path]);
|
||||
|
||||
// Compute the path using NavMeshQuery
|
||||
useEffect(() => {
|
||||
if (!navMesh || selectedPoints.length === 0) return;
|
||||
|
||||
@@ -119,17 +122,22 @@ export default function PathNavigator({
|
||||
if (!isWaiting.current) {
|
||||
isWaiting.current = true; // Set waiting flag
|
||||
|
||||
setTimeout(() => {
|
||||
progressRef.current = 0; // Reset progress
|
||||
movingForward.current = !movingForward.current; // Toggle direction
|
||||
|
||||
// Reverse the path and distances arrays
|
||||
path.reverse();
|
||||
distancesRef.current.reverse();
|
||||
|
||||
// Reset the waiting flag
|
||||
isWaiting.current = false;
|
||||
}, delayTime * 1000); // Convert seconds to milliseconds
|
||||
if (movingForward.current) {
|
||||
// Moving forward: reached the end, wait for `delay`
|
||||
// console.log(
|
||||
// "Reached end position. Waiting for delay:",
|
||||
// delayTime,
|
||||
// "seconds"
|
||||
// );
|
||||
setTimeout(() => {
|
||||
// After delay, reverse direction
|
||||
movingForward.current = false;
|
||||
progressRef.current = 0; // Reset progress
|
||||
path.reverse(); // Reverse the path
|
||||
distancesRef.current.reverse();
|
||||
isWaiting.current = false; // Reset waiting flag
|
||||
}, delayTime * 1000); // Wait for `delay` seconds
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -154,7 +162,7 @@ export default function PathNavigator({
|
||||
findObject.position.copy(startPoint);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
{path.length > 0 && (
|
||||
|
||||
Reference in New Issue
Block a user