class CP1Cannon : ZilchComponent { //This script is applied to your bullet spawner (named Cannon). //Your bullet spawner should be the child of your player object. [Property] var Projectile : Archetype = null; // What we are shooting [Property] var ShotSpeed : Real = 20; // How fast we are shooting it function Initialize(init : CogInitializer) { Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate); } function OnLogicUpdate(updateEvent : UpdateEvent) { if (Zero.Keyboard.KeyIsPressed(Keys.Space)) { // Create the bullet at the Player's location var bullet = this.Space.CreateAtPosition(this.Projectile, this.Owner.Transform.Translation); // Make sure it was created if (bullet != null) { // Get the direction of the player var direction = this.Owner.Orientation.WorldForward; // Make sure we only get the direction of the vector direction = Math.Normalize(direction); // Make the bullet go in that direction and scaled by the shot speed bullet.RigidBody.Velocity = direction * this.ShotSpeed; } } } }