So I'm spawning an explosion model with a velocity, represented by a little dot.
This model spawns several other smoke models with their own velocity.
All the smoke should follow the explosion velocity / direction, all while slowing down their own relative velocity after a second.
My problem is that with this little formula, the smoke velocity should regain the explosion velocity and continue it's way out of the screen with the little dot, but instead, it slows down to zero, and I don't understand why:
Code: Select all
CurrentModel.Velocity.X += (CurrentModel.ParentVelocity[0] - CurrentModel.Velocity.X) * 0.01;
CurrentModel.Velocity.Y += (CurrentModel.ParentVelocity[1] - CurrentModel.Velocity.Y) * 0.01;
Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
<OnRender>
<KeyPress Keys=" " RepeatDelay="0.2">
<OnPressed>
<ZExpression>
<Expression>
<![CDATA[ExplosionModel.Position.X = 0;
ExplosionModel.Position.Y = 0;
ExplosionModel.Position.Z = -30;
ExplosionModel.Velocity.X = random(0,5);
ExplosionModel.Velocity.Y = random(0,5);
ExplosionModel.Scale = 0.2;
ExplosionColor.Color = rnd();
createModel(ExplosionModel);]]>
</Expression>
</ZExpression>
</OnPressed>
</KeyPress>
</OnRender>
<Content>
<Model Name="ExplosionModel" Position="0 0 -30" Velocity="-8.3256 -0.6193 0">
<OnSpawn>
<ZExpression>
<Expression>
<![CDATA[for (int i=0; i<random(10,4); i++)
{
SmokeModel.Position.X = 0;
SmokeModel.Position.Y = 0;
SmokeModel.Position.Z = -30;
SmokeModel.ParentVelocity[0] = CurrentModel.Velocity.X;
SmokeModel.ParentVelocity[1] = CurrentModel.Velocity.Y;
SmokeModel.Velocity.X = SmokeModel.ParentVelocity[0] + random(0,1);
SmokeModel.Velocity.Y = SmokeModel.ParentVelocity[1] + random(0,1);
SmokeColor.Color = ExplosionColor.Color;
SmokeModel.SmokeScale = 1 + 2*rnd();
SmokeModel.Scale = 0;
createModel(SmokeModel);
}]]>
</Expression>
</ZExpression>
</OnSpawn>
<OnUpdate>
<ZExpression>
<Expression>
<![CDATA[if (CurrentModel.Position.X < -20 || CurrentModel.Position.X > 20 || CurrentModel.Position.Y < -20 || CurrentModel.Position.Y > 20)
{
@RemoveModel();
}]]>
</Expression>
</ZExpression>
</OnUpdate>
<OnRender>
<RenderSetColor Name="ExplosionColor" Color="1 0.502 0.7529 1"/>
<RenderSprite/>
</OnRender>
</Model>
<Model Name="SmokeModel">
<Definitions>
<Variable Name="SmokeTimer"/>
<Variable Name="SmokeScale"/>
<Array Name="ParentVelocity" SizeDim1="2"/>
</Definitions>
<OnUpdate>
<ZExpression>
<Expression>
<![CDATA[CurrentModel.SmokeTimer += App.DeltaTime;
if (CurrentModel.SmokeTimer < 0.5)
{
// Get bigger
CurrentModel.Scale.X += (CurrentModel.SmokeScale - CurrentModel.Scale.X) * 0.2;
CurrentModel.Scale.Y = CurrentModel.Scale.Z = CurrentModel.Scale.X;
}
else
{
// Slow down
CurrentModel.Velocity.X += (CurrentModel.ParentVelocity[0] - CurrentModel.Velocity.X) * 0.01;
CurrentModel.Velocity.Y += (CurrentModel.ParentVelocity[1] - CurrentModel.Velocity.Y) * 0.01;
// Get smaller
CurrentModel.Scale.X += (0 - CurrentModel.Scale.X) * 0.005;
CurrentModel.Scale.Y = CurrentModel.Scale.Z = CurrentModel.Scale.X;
if (CurrentModel.Scale.X < 0.1) @RemoveModel();
}]]>
</Expression>
</ZExpression>
</OnUpdate>
<OnRender>
<RenderSetColor Name="SmokeColor" Color="0.502 0.502 0.7529 1"/>
<RenderSprite/>
</OnRender>
</Model>
</Content>
</ZApplication>