Page 1 of 1

Simple Animator never reaches the goal

Posted: Wed Apr 01, 2015 2:28 am
by rrTea
In the example, the model should remove itself when variable "Age" reaches 1 ("Age" grows via Simple Animator, it is reflected on the Model's scale). However, this never happens.

If the "Smooth" tickbox of the Simple Animator is turned on, it works as expected.

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FrameRateStyle="2" FixedFrameRate="60" NoSound="1">
  <OnLoaded>
    <SpawnModel Model="Floater"/>
  </OnLoaded>
  <Content>
    <Model Name="Floater">
      <Definitions>
        <Variable Name="Age"/>
      </Definitions>
      <OnUpdate>
        <AnimatorSimple Duration="1" AutoStart="255" Target="Age" ToValue="1"/>
        <Condition Comment="Remove?">
          <Expression>
<![CDATA[return
(
Age == 1
);]]>
          </Expression>
          <OnTrue>
            <RemoveModel/>
          </OnTrue>
          <OnFalse>
            <ZExpression Expression="CurrentModel.Scale = sin(Age/2*PI);"/>
          </OnFalse>
        </Condition>
      </OnUpdate>
      <OnRender>
        <UseMaterial Material="PaintDot"/>
        <RenderSetColor Color="1 0.502 0 1"/>
        <RenderSprite/>
      </OnRender>
    </Model>
    <Group Comment="Materials">
      <Children>
        <Material Name="PaintDot" Blend="1">
          <Textures>
            <MaterialTexture Texture="DotWhite" TextureWrapMode="1" TexCoords="1"/>
          </Textures>
        </Material>
      </Children>
    </Group>
    <Group Comment="Bitmaps">
      <Children>
        <Bitmap Name="DotWhite" Filter="1">
          <Producers>
            <BitmapExpression>
              <Expression>
<![CDATA[// Local variables

float X1, Y1, B, S;

// Distance from center ( per axis )

X1 = 0.5-x;
Y1 = 0.5-y;

B = 64/1; // 64 = BitmapSize | 2 = Anti-Aliasing bias ( in pixels )

pixel.A = B*0.5-sqrt(X1*X1+Y1*Y1)*B;

// Set RGB to white

pixel.R = 1;
pixel.G = 1;
pixel.B = 1;]]>
              </Expression>
            </BitmapExpression>
          </Producers>
        </Bitmap>
      </Children>
    </Group>
  </Content>
</ZApplication>

Posted: Wed Apr 01, 2015 10:48 am
by VilleK
I noticed that in this case the Age variable actually passes 1.0 slightly. I've fixed it so that the animator should be guaranteed to stop at the end value. Please update the beta and try again. Btw, it can be unreliable to test floating point values with the "==" condition. Better use ">=1" or similar.

Posted: Wed Apr 01, 2015 12:15 pm
by Kjell
Hi guys,
VilleK wrote:Btw, it can be unreliable to test floating point values with the "==" condition. Better use ">=1" or similar.
Depends a bit on how you look at it / the situation. For instance, even though "foo = 1 + 3.99" actually assigns a value of ≈4.989999744 to foo, the statement "if(foo == 4.99)" will still result in TRUE because the value you're comparing to has the exact same imprecision.

@rrTea - Are you sure you want to use nearest neighbor filtering with a "anti-aliased" texture? :wink:

K

Posted: Thu Apr 02, 2015 1:07 am
by rrTea
Ville: You're right, and thanks for the new version!

Kjell: Oh you're right, I guess it just carried over when I was pasting this from my main project. Although in this particular case it was actually useful because it helped to see that the size was slightly off.