Flee when the wolf howls
Updated
Six wandering, flocking sheep each get a Steering Flee from a script, disabled until the wolf howls: then fleeing outweighs the other behaviours and the flock scatters.
Press Howl: the sheep run from the amber wolf until they are 12 m away. Press Wolf leaves and they drift back together. Drag to orbit the camera, scroll to zoom.
Flee when the wolf howls
#pragma lifecycle(startup)
function startup() { const flee = new SteeringFleeComponent({ target: 'Wolf', panicDistance: 12, weight: 3 }); self.parent.addComponent(flee); flee.setEnabled(false);
on('wolf/howl', () => flee.setEnabled(true)); on('wolf/gone', () => flee.setEnabled(false));}#pragma lifecycle(startup)
function startup() { const flee = new SteeringFleeComponent({ target: 'Wolf', panicDistance: 12, weight: 3 }); self.parent.addComponent(flee); flee.setEnabled(false);
on('wolf/howl', () => flee.setEnabled(true)); on('wolf/gone', () => flee.setEnabled(false));}#pragma lifecycle(startup)
function startup() { const flee = new SteeringFleeComponent({ target: 'Wolf', panicDistance: 12, weight: 3 }); self.parent.addComponent(flee); flee.setEnabled(false);
on('wolf/howl', () => flee.setEnabled(true)); on('wolf/gone', () => flee.setEnabled(false));}#pragma lifecycle(startup)
function startup() { const flee = new SteeringFleeComponent({ target: 'Wolf', panicDistance: 12, weight: 3 }); self.parent.addComponent(flee); flee.setEnabled(false);
on('wolf/howl', () => flee.setEnabled(true)); on('wolf/gone', () => flee.setEnabled(false));}#pragma lifecycle(startup)
function startup() { const flee = new SteeringFleeComponent({ target: 'Wolf', panicDistance: 12, weight: 3 }); self.parent.addComponent(flee); flee.setEnabled(false);
on('wolf/howl', () => flee.setEnabled(true)); on('wolf/gone', () => flee.setEnabled(false));}#pragma lifecycle(startup)
function startup() { const flee = new SteeringFleeComponent({ target: 'Wolf', panicDistance: 12, weight: 3 }); self.parent.addComponent(flee); flee.setEnabled(false);
on('wolf/howl', () => flee.setEnabled(true)); on('wolf/gone', () => flee.setEnabled(false));}How it works
Section titled “How it works”The script is explained step by step in Flee when the wolf howls.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
SheepFlee.xrproj