移動 Actors
設置 Actor 的變換
@Actor()
class BallActor extends BaseActor {
private physics = inject(PhysicsSystem)
public speed = 0.4
public direction = new THREE.Vector3(0,0,1)
private mesh = attach(MeshComponent, {
mass: 1,
bodyType: PhysicsBodyType.static,
object: new PhysicalShapeMesh(
new SphereGeometry(.2, 20, 10),
new MeshStandardMaterial({ color: 0xeff542 }),
new SphereCollisionShape(.2))
})
onUpdate(deltaTime: number) {
this.position.addScaledVector(this.direction, this.speed * deltaTime)
// Also update the physics system so that the physics body is updated
this.physics.updateActorTransform(this)
}
}最后更新于