Modding:Simple Particles

From Vintage Story Wiki
Revision as of 11:01, 31 October 2017 by CreativeMD (talk | contribs)

VintageStory offers a variety of different types of particles. This tutorial will explain you how to create particles in code and show you some of the possibilities. If you want to have an example of where to use them I either suggested you to the read about the block particles or about collectibles. <- Add links

SimpleParticleProperties

Spawn particles

So let's spawn some really basic particles. I suggest to create a static field for your particle properties:

        public static SimpleParticleProperties myParticles = new SimpleParticleProperties(1, 1, ColorUtil.ColorFromArgb(50, 220, 220, 220), new Vec3d(), new Vec3d(), new Vec3f(), new Vec3f());

Now we have the property, the only thing what is left to do is to set the position and spawn them into the world. I'm gonna use the OnInteracting method inside the Item class (you can read more about this in the Collectibles Tutorial):

        public override bool OnInteracting(float secondsUsed, IItemSlot slot, IEntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            myParticles.minPos = byEntity.Pos.XYZ.Add(0, byEntity.EyeHeight(), 0).Ahead(1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw);
            byEntity.World.SpawnParticles(myParticles);
        }

This will spawn some white cube particles, which simply fall to the ground. They are spawned right in front of the player.

BasicParticles.png

Properties Overview

There are several things you can configure. Here is an overview which covers all of the basics properties:

Position

Basically there are two properties. One of the is the minPos property, which will determine the exact position where it will spawn. All particles will spawn there if addPos is not defined.

Velocity

Life length

Quantity

Color

Glow

Opacity

Model

Gravity

Die In Air/ Liquid

Other Particles

AirBubbleParticles

BlockVoxelParticles

ExplosionParticles

WaterSplashParticles