Particles with Gravity.Z

All topics about ZGameEditor goes here.

Moderator: Moderators

User avatar
Ats
Posts: 127
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Particles with Gravity.Z

Postby Ats » Sun Jul 01, 2018 4:43 am

Hi, I'm trying to add a smoke trail behind my ships and missiles, but I can't make the particles to move with gravity over the Z axis, even though this option can be set up. It only works for the X and Y axis. Here's an example:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnUpdate>
    <Timer Interval="3">
      <OnTimer>
        <ZExpression>
          <Expression>
<![CDATA[model m = createModel(EnemyMissile);
m.Position.X = random(0,5);
m.Position.Y = random(0,5);
m.Position.Z = -100;]]>
          </Expression>
        </ZExpression>
      </OnTimer>
    </Timer>
  </OnUpdate>
  <Content>
    <Mesh Name="EnemyMissileMesh">
      <Producers>
        <MeshBox Comment="tube" Scale="0.3 0.3 2"/>
        <MeshExpression VertexColors="255">
          <Expression>
<![CDATA[c.R=0.8;
c.G=0.8;
c.B=0.8;]]>
          </Expression>
        </MeshExpression>
        <MeshBox Comment="flaps vertical" Scale="0.1 1 1"/>
        <MeshExpression VertexColors="255">
          <Expression>
<![CDATA[c.R=1;
c.G=0.2;
c.B=0.2;]]>
          </Expression>
        </MeshExpression>
        <MeshTransform Scale="1 0.8 0.8" Position="0 0 0.86" Rotation="0.875 0 0"/>
        <MeshCombine/>
        <MeshBox Comment="flaps horizontal" Scale="0.1 1 1"/>
        <MeshExpression VertexColors="255">
          <Expression>
<![CDATA[c.R=1;
c.G=0.2;
c.B=0.2;]]>
          </Expression>
        </MeshExpression>
        <MeshTransform Scale="1 0.8 0.8" Position="0 0 0.86" Rotation="0.875 0 0.25"/>
        <MeshCombine/>
        <MeshSphere Comment="head" Scale="0.4 0.4 0.8" ZSamples="3" RadialSamples="4"/>
        <MeshExpression VertexColors="255">
          <Expression>
<![CDATA[c.R=1;
c.G=0.2;
c.B=0.2;]]>
          </Expression>
        </MeshExpression>
        <MeshTransform Scale="1.06 1.06 1.6" Position="0 0 -2" Rotation="0 0 0.125"/>
        <MeshCombine/>
      </Producers>
    </Mesh>
    <Model Name="EnemyMissile" Category="2" CollisionBounds="0.6 0.6 3 0" CollisionOffset="0 0 -0.5" CollisionStyle="2" RenderOrder="1">
      <OnSpawn>
        <ZExpression>
          <Expression>
<![CDATA[CurrentModel.Rotation.Y = .5;
CurrentModel.Velocity.Z = 20;]]>
          </Expression>
        </ZExpression>
      </OnSpawn>
      <OnUpdate>
        <Condition Comment="Exit" Expression="return CurrentModel.Position.Z &gt; 10;">
          <OnTrue>
            <RemoveModel/>
          </OnTrue>
          <OnFalse>
            <ZExpression>
              <Expression>
<![CDATA[CurrentModel.RotationVelocity.Z += .005;
CurrentModel.Velocity.Z += .2;]]>
              </Expression>
            </ZExpression>
          </OnFalse>
        </Condition>
      </OnUpdate>
      <OnRender>
        <UseMaterial Material="FlatMaterial"/>
        <RenderMesh Mesh="EnemyMissileMesh"/>
        <UseMaterial Material="SmokeMaterial"/>
        <RenderTransform Translate="0 0 1"/>
        <RenderParticles ParticlesPerSecond="4" ParticleWidth="6" ParticleHeight="6" ParticleLifetime="3" AnimateSize="-1" Gravity="0 0 -5" FollowModel="0">
          <OnEmitExpression>
<![CDATA[//Emit particle.
//PColor : particle color, PAngle : particle angle
this.PColor = vector3(.5,.5,.5);]]>
          </OnEmitExpression>
        </RenderParticles>
      </OnRender>
    </Model>
    <Material Name="FlatMaterial" Shading="1"/>
    <Bitmap Name="SmokeBitmap" Width="16" Height="16" Filter="2">
      <Producers>
        <BitmapRect/>
        <BitmapBlur Radius="1"/>
        <BitmapZoomRotate/>
      </Producers>
    </Bitmap>
    <Material Name="SmokeMaterial" Shading="1" Light="0" SpecularColor="0 0 0 1" EmissionColor="0 0 0 1" Blend="2" DrawBackFace="255">
      <Textures>
        <MaterialTexture Texture="SmokeBitmap" TexCoords="1"/>
      </Textures>
    </Material>
  </Content>
</ZApplication>

(I love those copy/paste projects as text)

User avatar
Kjell
Posts: 1644
Joined: Sat Feb 23, 2008 11:15 pm

Re: Particles with Gravity.Z

Postby Kjell » Sun Jul 01, 2018 9:26 am

Hi Ats,

RenderParticles is a 2D-only component .. which means that the Z component* of the Gravity property is ignored. And even when you disable the FollowModel property particles still follow the model from which they are spawned on the Z-axis ( see demonstration example below ).

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" CameraPosition="0 16 16" CameraRotation="0.125 0 0" FileVersion="2">
  <OnLoaded>
    <SpawnModel Model="Box"/>
  </OnLoaded>
  <Content>
    <Model Name="Box">
      <OnUpdate>
        <ZExpression>
          <Expression>
<![CDATA[//

Box.Position.X = sin(App.Time)*8;
Box.Position.Z = cos(App.Time)*8;]]>
          </Expression>
        </ZExpression>
      </OnUpdate>
      <OnRender>
        <UseMaterial Material="BoxMaterial"/>
        <RenderMesh Mesh="BoxMesh"/>
        <UseMaterial Material="CircleMaterial"/>
        <RenderParticles ParticlesPerSecond="8" ParticleWidth="0.5" ParticleHeight="0.5" ParticleLifetime="2" AnimateAlpha="-0.5" FollowModel="0"/>
      </OnRender>
    </Model>
    <Mesh Name="BoxMesh">
      <Producers>
        <MeshBox/>
      </Producers>
    </Mesh>
    <Material Name="BoxMaterial"/>
    <Bitmap Name="CircleBitmap">
      <Producers>
        <BitmapExpression>
          <Expression>
<![CDATA[//

float u, v;

u = 0.5-X;
v = 0.5-Y;

Pixel.R = 1;
Pixel.G = 1;
Pixel.B = 1;
Pixel.A = 16-sqrt(u*u+v*v)*32;]]>
          </Expression>
        </BitmapExpression>
      </Producers>
    </Bitmap>
    <Material Name="CircleMaterial" Shading="1" Light="0" Blend="2">
      <Textures>
        <MaterialTexture Texture="CircleBitmap" TexCoords="1"/>
      </Textures>
    </Material>
  </Content>
</ZApplication>

If you want a 3D particle system the best option right now is to "roll your own".

*In programming the individual variables in a structure are referred to as components .. but because ZGE also calls the building-blocks of the project tree components this can be a little confusing semantically.

K

User avatar
Ats
Posts: 127
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Particles with Gravity.Z

Postby Ats » Sun Jul 01, 2018 10:39 am

All right. MAybe VilleK should remove (or repair) this, because it's very confusing...

Image

User avatar
Kjell
Posts: 1644
Joined: Sat Feb 23, 2008 11:15 pm

Re: Particles with Gravity.Z

Postby Kjell » Sun Jul 01, 2018 11:09 am

Hi Ats,

Agreed .. as long as the Z component isn't used, there shouldn't be a field for it in the editor either. It is mentioned on the help page though :wink:

K

User avatar
Ats
Posts: 127
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Particles with Gravity.Z

Postby Ats » Sun Jul 01, 2018 12:15 pm

Sorry but the Help page is another problem I have with ZGE: it's hard to decipher. Since it is some kind of wiki, I would gladly improve the readability of it. Furthermore, most of the newest informations are on the forum so it's not simple to retrieve them.

Anyway, here's my new missile that creates smoke as models. Is that ok? Or would it be too heavy? (since it creates a bunch of models per second)

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnUpdate>
    <Timer Interval="3">
      <OnTimer>
        <ZExpression>
          <Expression>
<![CDATA[model m = createModel(EnemyMissile);
m.Position.X = random(0,5);
m.Position.Y = random(0,5);
m.Position.Z = -100;]]>
          </Expression>
        </ZExpression>
      </OnTimer>
    </Timer>
  </OnUpdate>
  <Content>
    <Mesh Name="EnemyMissileMesh">
      <Producers>
        <MeshBox Comment="tube" Scale="0.3 0.3 2"/>
        <MeshExpression VertexColors="255">
          <Expression>
<![CDATA[c.R=0.8;
c.G=0.8;
c.B=0.8;]]>
          </Expression>
        </MeshExpression>
        <MeshBox Comment="flaps vertical" Scale="0.1 1 1"/>
        <MeshExpression VertexColors="255">
          <Expression>
<![CDATA[c.R=1;
c.G=0.2;
c.B=0.2;]]>
          </Expression>
        </MeshExpression>
        <MeshTransform Scale="1 0.8 0.8" Position="0 0 0.86" Rotation="0.875 0 0"/>
        <MeshCombine/>
        <MeshBox Comment="flaps horizontal" Scale="0.1 1 1"/>
        <MeshExpression VertexColors="255">
          <Expression>
<![CDATA[c.R=1;
c.G=0.2;
c.B=0.2;]]>
          </Expression>
        </MeshExpression>
        <MeshTransform Scale="1 0.8 0.8" Position="0 0 0.86" Rotation="0.875 0 0.25"/>
        <MeshCombine/>
        <MeshSphere Comment="head" Scale="0.4 0.4 0.8" ZSamples="3" RadialSamples="4"/>
        <MeshExpression VertexColors="255">
          <Expression>
<![CDATA[c.R=1;
c.G=0.2;
c.B=0.2;]]>
          </Expression>
        </MeshExpression>
        <MeshTransform Scale="1.06 1.06 1.6" Position="0 0 -2" Rotation="0 0 0.125"/>
        <MeshCombine/>
      </Producers>
    </Mesh>
    <Model Name="EnemyMissile" Category="2" CollisionBounds="0.6 0.6 3 0" CollisionOffset="0 0 -0.5" CollisionStyle="2" RenderOrder="1">
      <OnSpawn>
        <ZExpression>
          <Expression>
<![CDATA[CurrentModel.Rotation.Y = .5;
CurrentModel.Velocity.Z = 20;]]>
          </Expression>
        </ZExpression>
      </OnSpawn>
      <OnUpdate>
        <Condition Comment="Exit" Expression="return CurrentModel.Position.Z &gt; 10;">
          <OnTrue>
            <RemoveModel/>
          </OnTrue>
          <OnFalse>
            <ZExpression>
              <Expression>
<![CDATA[CurrentModel.RotationVelocity.Z += .005;
CurrentModel.Velocity.Z += .2;]]>
              </Expression>
            </ZExpression>
          </OnFalse>
        </Condition>
        <Timer Interval="0.05">
          <OnTimer>
            <SpawnModel Model="SmokeModel" Position="0 0 -2" UseSpawnerPosition="255"/>
          </OnTimer>
        </Timer>
      </OnUpdate>
      <OnRender>
        <UseMaterial Material="FlatMaterial"/>
        <RenderMesh Mesh="EnemyMissileMesh"/>
      </OnRender>
    </Model>
    <Material Name="FlatMaterial" Shading="1"/>
    <Bitmap Name="SmokeBitmap" Width="16" Height="16" Filter="2">
      <Producers>
        <BitmapRect/>
        <BitmapBlur Radius="1"/>
      </Producers>
    </Bitmap>
    <Material Name="SmokeMaterial" Shading="1" Light="0" SpecularColor="0 0 0 1" EmissionColor="0 0 0 1" Blend="2" DrawBackFace="255">
      <Textures>
        <MaterialTexture Texture="SmokeBitmap" TexCoords="1"/>
      </Textures>
    </Material>
    <Mesh Name="SmokeMesh">
      <Producers>
        <MeshBox Grid2DOnly="255"/>
      </Producers>
    </Mesh>
    <Model Name="SmokeModel">
      <OnSpawn>
        <ZExpression Expression="CurrentModel.Scale.X = CurrentModel.Scale.Y = 2;"/>
      </OnSpawn>
      <OnUpdate>
        <ZExpression>
          <Expression>
<![CDATA[if (CurrentModel.Scale.X > 0)
{
  CurrentModel.Scale.Y = CurrentModel.Scale.X -= .04;
} else {
  @RemoveModel();
}]]>
          </Expression>
        </ZExpression>
      </OnUpdate>
      <OnRender>
        <UseMaterial Material="SmokeMaterial"/>
        <RenderMesh Mesh="SmokeMesh"/>
      </OnRender>
    </Model>
  </Content>
</ZApplication>

User avatar
Kjell
Posts: 1644
Joined: Sat Feb 23, 2008 11:15 pm

Re: Particles with Gravity.Z

Postby Kjell » Sun Jul 01, 2018 10:30 pm

Hi Ats,

Ats wrote:Anyway, here's my new missile that creates smoke as models. Is that ok? Or would it be too heavy?

That's certainly not the most lightweight approach to particles ( using a model per particle ). But as long as your game runs at the desired frame-rate on the weakest hardware that you want to support, it doesn't really matter anyway :wink:

K


Return to “General discussion”

Who is online

Users browsing this forum: No registered users and 2 guests