How to create dust for ranged weapon ?

You want to spawn dust on the player body, or on the projectile ?
And you're using tmodloader, right ?
Yes . i use tmodloader.
Yes i want spawn dust on weapon that i use when i shoot, that will be more correctly. Not projectile.
I wanna make something like smoke after shoot. or bullet casing that flying arround after shoot.
And i very interesting how to create animation for gun - example : minigun spinning barrels when its shooting.
:)
 
Last edited:
You can use this, in the ITEM.cs file of your weapon.
C#:
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)

        {

            Vector2 muzzleOffset = Vector2.Normalize(new Vector2(speedX, speedY)) * 64f;

            if (Collision.CanHit(position, 0, 0, position + muzzleOffset, 0, 0))

                position += muzzleOffset;



         

            int dustQuantity = 5; // How many particles do you want ?

            for(int i = 0 ; i < dustQuantity ; i ++)

            {

                Vector2 dustOffset = Vector2.Normalize(new Vector2(speedX, speedY)) * 32f;

                int dust = Dust.NewDust(player.position + dustOffset, item.width, item.height, 6); // Create the dust, "6" is the dust type (fire, in that case).

             

                Main.dust[dust].noGravity = true; // Is the dust affected by gravity ?

                Main.dust[dust].velocity *= 1f;    // Change the dust velocity.

                Main.dust[dust].scale = 1.5f;    // Change the dust size.

            }

         

            return true; // Do you want the weapon to shoot the initial projectile ?

        }

It will spawn dust on the weapon when used, feel free to change it however you need to.
 
You can use this, in the ITEM.cs file of your weapon.
C#:
        public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)

        {

            Vector2 muzzleOffset = Vector2.Normalize(new Vector2(speedX, speedY)) * 64f;

            if (Collision.CanHit(position, 0, 0, position + muzzleOffset, 0, 0))

                position += muzzleOffset;



        

            int dustQuantity = 5; // How many particles do you want ?

            for(int i = 0 ; i < dustQuantity ; i ++)

            {

                Vector2 dustOffset = Vector2.Normalize(new Vector2(speedX, speedY)) * 32f;

                int dust = Dust.NewDust(player.position + dustOffset, item.width, item.height, 6); // Create the dust, "6" is the dust type (fire, in that case).

            

                Main.dust[dust].noGravity = true; // Is the dust affected by gravity ?

                Main.dust[dust].velocity *= 1f;    // Change the dust velocity.

                Main.dust[dust].scale = 1.5f;    // Change the dust size.

            }

        

            return true; // Do you want the weapon to shoot the initial projectile ?

        }

It will spawn dust on the weapon when used, feel free to change it however you need to.
Wow thank you very much !!
 
Back
Top Bottom