struct GameSystem: System {
static let rootQuery = EntityQuery(where: .has(GameMoveComponent.self) )
init(scene: RealityKit.Scene) { }
func update(context: SceneUpdateContext) {
let root = context.scene.performQuery(Self.rootQuery)
for entity in root{
let game = entity.components[GameMoveComponent.self]!
if let xMove = game.game.gc?.extendedGamepad?.dpad.xAxis.value ,
let yMove = game.game.gc?.extendedGamepad?.dpad.yAxis.value {
print("x:\(xMove),y:\(yMove)")
let x = entity.transform.translation.x + xMove * 0.01
let y = entity.transform.translation.z - yMove * 0.01
entity.transform.translation = [x , entity.transform.translation.y , y]
}
}
}
}
I want to use the game controller's direction keys to control the continuous movement of Entity in visionOS. When I added a query for handle button presses in the ECS System, I found that the update interface was not called at a frequency of 30 frames per second. Instead, it executes once when I press or release the key.
Is this what is the reason?
I want to keep moving by holding down the controller button, is there a better solution? I hope this moving process will be smooth and not stuck.