Skip to content

Instantly share code, notes, and snippets.

View mecha-moonboy's full-sized avatar
🧙‍♂️
Creating

mecha_moonboy mecha-moonboy

🧙‍♂️
Creating
View GitHub Profile
// The [makeBullets()] function was called earlier. It calls for an amount of bullets, an amount of damage that each bullet will deal, an origin point,
// another point to shoot towards, a float for a range, a float for the max spread, and a float for knockback force.
public void makeBullets ( int Quantity , int Damage, Vector2 Origin, Vector2 Direction, float Range, float Spread = 0f, float KnockBack = 0.0f){
// This entire for loop repeats for each bullet being created.
for( int i = Quantity ; i > 0 ; i-- ){
// Gets the point where the ray will end. Uses normalized [Direction], adds a random value to it multiplied by the [Spread],
// which means if spread is zero, the bullets will fly perfectly straight.
Vector2 rayEnd = new Vector2( (Direction.normalized.x + (Random.value - 0.5f) * Spread) * (Range + rangeMod), (Direction.normalized.y + (Random.value - 0.5f) * Spread) * (Range + rangeMod));
// The [makeBullets()] function was called earlier. It calls for an amount of bullets, an amount of damage that each bullet will deal, an origin point,
// another point to shoot towards, a float for a range, a float for the max spread, and a float for knockback force.
public void makeBullets ( int Quantity , int Damage, Vector2 Origin, Vector2 Direction, float Range, float Spread = 0f, float KnockBack = 0.0f){
// This entire for loop repeats for each bullet being created.
for( int i = Quantity ; i > 0 ; i-- ){
// Gets the point where the ray will end. Uses normalized [Direction], adds a random value to it multiplied by the [Spread],
// which means if spread is zero, the bullets will fly perfectly straight.
Vector2 rayEnd = new Vector2( (Direction.normalized.x + (Random.value - 0.5f) * Spread) * (Range + rangeMod), (Direction.normalized.y + (Random.value - 0.5f) * Spread) * (Range + rangeMod));