Class PlayerShoot : ZilchComponent { [Property] var BulletSpawnDistanceFromPlayer : Real = 1.0; //This script uses your spacebar to shot the ball/projectile [Property] var ShotSpeed : Integer = 20; function Initialize(init : CogInitializer) { var gamecamera = this.Space.FindObjectByName("Camera"); Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate); } function OnLogicUpdate(event : UpdateEvent) { var direction = this.Owner.Orientation.WorldForward; direction = Math.Normalize(direction); var position = this.Owner.Transform.WorldTranslation + (direction * this.BulletSpawnDistanceFromPlayer); var positionL = this.Owner.Transform.WorldTranslation + (-direction * this.BulletSpawnDistanceFromPlayer); var spawnPosition = this.Owner.Transform.Translation; //Change Archetype.PlayerBullet to whatever projectile you are using var archetypeToSpawn = Archetype.PlayerBullet; if(Zero.Keyboard.KeyIsPressed(Keys.Space)) { //if the sprite is facing left then the projectile will shoot left here if(this.Owner.Sprite.FlipX == true) { var createdBallL = this.Space.CreateAtPosition(archetypeToSpawn, positionL); createdBallL.RigidBody.Velocity = -this.Owner.Orientation.WorldForward * this.ShotSpeed; createdBallL.Sprite.FlipX = true; } //otherwise it will shoot to the right else { var createdBall = this.Space.CreateAtPosition(archetypeToSpawn, position); createdBall.RigidBody.Velocity = this.Owner.Orientation.WorldForward * this.ShotSpeed; } } } }