Simple Animator never reaches the goal

Found a bug? Post information about it here so we can fix it!

Moderator: Moderators

Post Reply
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Simple Animator never reaches the goal

Post 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>
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post 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.
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Post 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.
Post Reply