Boffin
Brain of Cthulhu
You'd override the item's PreShoot method, like the person above said. This sounds like a fun and short puzzle, so I'll just make this code. I imagine it would go something like this:
Code:public override bool PreShoot(Player player, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { float magnitude = (float)Math.Sqrt(velocity.X * velocity.X + velocity.Y * velocity.Y); //Pythagorean theorem to get the speed float rotation = Math.Atan2(velocity.Y, velocity.X); //gets the theta coordinate of the velocity's polar coordinates, aka angle in radians float direction = rotation * 4f / (float)Math.PI; //there are 8 directions, so we want this to range from 0 to 8 float newRotation = (float)Math.Round(direction) / 4f * (float)Math.PI; //convert to a specific direction velocity.X = (float)Math.Cos(newRotation) * magnitude; //converting polar coordinates to Cartesian coordinates velocity.Y = (float)Math.Sin(newRotation) * magnitude; //same thing Projectile.NewProjectile(position.X, position.Y, velocity.X, velocity.Y, type, damage, knockback, Main.myPlayer); //finally create the projectile return false; //we already created the projectile, so the game doesn't need to do it for us }
I know this was posted ages ago, but I'd like to ask how you could achieve something similar but make it shoot out of a boss, as part of an attack. I have a worm boss, and in a feeble attempt to make it unique, I'd like to add this code (8 or so projectiles shooting out of the bosses head)