Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
}
let rotatingCubes = engine.getComponentGroup(ObjectRotation)
export class ObjectRotationSystem implements ISystem {
update(dt: number) {
for (let cubeEntity of rotatingCubes.entities) {
let rotationComponent = cubeEntity.getComponent(ObjectRotation)
let transform = cubeEntity.getComponent(Transform)
transform.rotate(rotationComponent.rotationAxis, rotationComponent.speed * dt)
}
}
}
let rotationSystem = new ObjectRotationSystem()
engine.addSystem(rotationSystem)
let rotatingPlatformEntity = new Entity()
rotatingPlatformEntity.addComponentOrReplace(new BoxShape())
rotatingPlatformEntity.addComponentOrReplace(
new Transform({
position: new Vector3(2, 1, 2),
scale: new Vector3(5, 0.25, 1.5)
})
)
rotatingPlatformEntity.addComponentOrReplace(new ObjectRotation(10, new Vector3(0, 1, 0)))
engine.addEntity(rotatingPlatformEntity)
if(this.shouldSwitchDirection(movementData)) {
movementData.goingForward = !movementData.goingForward
}
movementData.targetWaypoint = movementData.currentWaypoint + (movementData.goingForward ? 1 : -1)
}
}
}
shouldSwitchDirection (movementData: PathMovement) {
return (movementData.goingForward && movementData.currentWaypoint == movementData.waypoints.length - 1) ||
(!movementData.goingForward && movementData.currentWaypoint == 0)
}
}
let movementSystem = new PingPongMovementSystem()
engine.addSystem(movementSystem)
export function configureShapeEntityPositions(waypointsPath: Vector3[], speed: number, shape: Shape) {
const entity = new Entity()
entity.addComponentOrReplace(shape)
entity.addComponentOrReplace(
new Transform({
position: waypointsPath[0]
}))
entity.addComponentOrReplace(new PathMovement(waypointsPath, speed))
engine.addEntity(entity)
return entity
}
configureShapeEntityPositions([new Vector3(-3, 1, -8), new Vector3(35, 1, -8)], 0.2, new NFTShape('ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536'))