fix(complement-race): use individual player positions for ghost trains
Previously all ghost trains used the local player's trainPosition, causing them to render at the same location (hidden behind local train). Now each ghost train uses its own player.position from multiplayer state, allowing them to be visible at different positions on the track. Also added logging to show ghost train positions for debugging. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -47,10 +47,10 @@ export function GhostTrain({ player, trainPosition, trackGenerator, pathRef }: G
|
||||
const hasLoggedRef = useRef(false)
|
||||
useEffect(() => {
|
||||
if (!hasLoggedRef.current && trainTransform.opacity > 0) {
|
||||
console.log('[GhostTrain] rendering:', player.name)
|
||||
console.log('[GhostTrain] rendering:', player.name, 'at position:', trainPosition.toFixed(1))
|
||||
hasLoggedRef.current = true
|
||||
}
|
||||
}, [trainTransform.opacity, player.name])
|
||||
}, [trainTransform.opacity, player.name, trainPosition])
|
||||
|
||||
// Don't render if position data isn't ready
|
||||
if (trainTransform.opacity === 0) {
|
||||
|
||||
@@ -217,7 +217,13 @@ export function SteamTrainJourney({
|
||||
// Log only when otherPlayers count changes
|
||||
useEffect(() => {
|
||||
console.log('[SteamTrainJourney] otherPlayers count:', otherPlayers.length)
|
||||
}, [otherPlayers.length])
|
||||
if (otherPlayers.length > 0) {
|
||||
console.log(
|
||||
'[SteamTrainJourney] ghost positions:',
|
||||
otherPlayers.map((p) => `${p.name}: ${p.position.toFixed(1)}`).join(', ')
|
||||
)
|
||||
}
|
||||
}, [otherPlayers.length, otherPlayers])
|
||||
|
||||
if (!trackData) return null
|
||||
|
||||
@@ -285,7 +291,7 @@ export function SteamTrainJourney({
|
||||
<GhostTrain
|
||||
key={player.id}
|
||||
player={player}
|
||||
trainPosition={trainPosition} // For now, use same position calculation
|
||||
trainPosition={player.position} // Use each player's individual position
|
||||
trackGenerator={trackGenerator}
|
||||
pathRef={pathRef}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user