[BEHAVIOR] Ease transition

Post your completed addons to share with the community

Post » Sun Jan 01, 2012 10:13 pm


Simple but subtly powerful behavior for doing eased interpolation between two points. Easing means the transition is smooth when close to the endpoints. This functionality is similar to the sine behavior but additional properties, expressions and actions make it more powerful.

Get the plugin here (ZIP)

The naive use of the behavior is to make an object "ping-pong" between two points.

Origin X,Origin Y
- the "ping" point
Destination X,Desitnation Y
- the "pong" point
Transition Period
- time taken to complete the transition

Actions:
- Move easing into (EaseIn)
    end of transition is smoothed
- Move easing away (EaseOut)
    beginning of transition is smoothed
- Move easing both (EaseInOut)
    both beginning and end of transition are smoothed

All three actions work in ping-pong fashion alternately
from call to call (first action called will go origin-to-dest, second destination-to-origin, third origin-to-destination, and so forth).
Call the action will no-op if a movement is already in place. The time lerp is independant of the position so changing the position should not lead to any sort of runaway object (non halting movement). The time lerp will clamp if out of bounds to the property setting if you mess with the transition period mid-movement. Do not set the transition period to exactly zero as it is sure to stop your game due to divide-by-zero (time fraction is calculated as current_elapsed/transition_period). Maybe there is a way to have the transition_period property reject any change that sets it exactly zero? I'm not quite sure how to go about it.


Additional Actions:
- Change origin endpoint
    Allows changing the origin endpoint at any time,
    even mid-transition.
- Change destination endpoint
    Allows changing the destination endpoint at any time,
    even mid-transition.
- Change transition period
    Allows changing the transition period to any nonzero value.
    Changing mid transition may cause clamping and snaps to return
    the values to the new range but it should not crash the game.

The endpoint actions can be used to do waypoint type movements or any sort of complicated pattern of bumps, shakes, etc. of an object.


Three conditions may be used for event to know the state of the transition:

- Is at destination
   object is at "ping"
- Is at origin
   object is at "pong"
- Is in transition (invertible to mean "Is stationary")
   object is moving (or inverted: not moving)

Expression for events:
- IsEasing
    1 if object is moving otherwise 0
    (expression form of Is in transition)
- GetTransition
    Returns the status of transition
    result is a float in range 0 to 1 inclusive
    0 matches IsAtOrigin condition
    1 matches IsAtDestination
    A more powerful feature is to use this expression
    to apply something other than movement to the object
    (eg: Set angle to -180*myObject.GauVeldt_Ease.GetTransition)

Triggers:
- On Endpoint Reached
    fires when object completes movement cycle
    Condition IsAtDestination/IsAtOrigin may be used in
    subevent or GetTransition may be used to know which
    endpoint the object is at
- On Update Tick
    this one is subtly very powerful as it provides the ideal
    trigger upon which to add actions using GetTransition to set
    other object properties (eg: visible, angle, etc). Sure
    you could do it in System:OnEveryTick but I think this is
    cleaner in practice (a system event would need a whole bunch
    of sub events to test the location, movement status, etc)

I think that's everything. One final possible improvement is to allow customization of the transition functions (there are three) EaseIn for the start of a transition, EaseOut for the end of a transition and EaseInOut for both. Right now the transition functions are internal but it could perhaps be modified to accept JS expressions in string properties using eval to compile to functions. That's for future consideration.

Edit:
PS: To do eased rotations or fades, etc., with no movement just set the origin and destination to the same point as its layout position. A TODO item is to add a movement-ignore flag for just these kinds of non-movement transitions.

Edit 2012.02.10:
Added Set Origin, Set Destination, and Set Period actions for changing the movement location via event sheet actions.GauVeldt2012-02-11 15:48:33
B
28
S
5
G
1
Posts: 30
Reputation: 1,889

Post » Sun Jan 01, 2012 10:28 pm

Can you provide a example capx? I cannot figure out how to use this.. I set a destination x and origin x but no movement :(
B
7
S
1
G
1
Posts: 32
Reputation: 881

Post » Sun Jan 01, 2012 10:36 pm

TODO: Add a Do-Not-Reposition boolean property to allow stacking the behavior for multiple effects with different durations. Think like Sonic where he spins up, flies across the layout map then slows down. The spin up/down can then be one behavior and the movement another but it won't work right if each Ease behavior tries to set position they'll fight with one another as each changes the object's X and Y. With this boolean any non movement Eases may be stacked with another behavior that does (eg: bullet or another ease with the Do-Not-Reposition property set False). One would be able to make swirling bullets (bullet behavior + ease that changes angle only) or blinking objects (ease that changes only translucency) with this property available.

Edit 2012.02.03:
TODO: Make transition properties (eg: originX, originY, destinationX, destinationY) accessible at run time either via properties (if plugins can do this) or set/get methods. Can any of the plugin veterans give me any advice on going about this?
- Suggested by TL22GauVeldt2012-02-03 23:50:03
B
28
S
5
G
1
Posts: 30
Reputation: 1,889

Post » Sun Jan 01, 2012 10:39 pm

[QUOTE=FlashDeveloper] Can you provide a example capx? I cannot figure out how to use this.. I set a destination x and origin x but no movement :([/QUOTE]

Unlike bullet the movement is not automatic. It is meant to be initiated by calling one of the EaseIn, EaseOut or EaseInOut actions on the behavior.

Adding a System->Do Every X seconds event is one way to trigger the action

Edit:
I'll make a capx to show that now...GauVeldt2012-01-01 22:41:24
B
28
S
5
G
1
Posts: 30
Reputation: 1,889

Post » Sun Jan 01, 2012 11:10 pm

[QUOTE=FlashDeveloper] Can you provide a example capx? I cannot figure out how to use this.. I set a destination x and origin x but no movement :([/QUOTE]

http://dl.dropbox.com/u/55284551/testEase.capx

Edit 2012.01.01 15:25
- cleaned up the capx slightly
GauVeldt2012-01-01 23:22:22
B
28
S
5
G
1
Posts: 30
Reputation: 1,889

Post » Fri Feb 03, 2012 4:01 pm

This is a really cool behavior. I was getting headaches with the sine behavior trying to make just a quick bounce, and this worked perfectly!

However it would make it much more powerful if you could change the origin and destination points and the other attributes mid-play. Are there any plans to add actions to change the attributes? Because if not, you should totally do that!

Thanks again for the behavior! Just what I needed!
B
58
S
20
G
7
Posts: 305
Reputation: 8,804

Post » Fri Feb 03, 2012 11:43 pm

I'll add access to the origin and destination properties and period to the TODO list on this. The code can already handle the case of changing origin and destination points internally but it doesn't yet expose the properties in order to allow it at runtime via set/get methods.
B
28
S
5
G
1
Posts: 30
Reputation: 1,889

Post » Fri Feb 10, 2012 10:20 pm

[QUOTE=TL22] This is a really cool behavior. I was getting headaches with the sine behavior trying to make just a quick bounce, and this worked perfectly!

However it would make it much more powerful if you could change the origin and destination points and the other attributes mid-play. Are there any plans to add actions to change the attributes? Because if not, you should totally do that!

Thanks again for the behavior! Just what I needed![/QUOTE]

Give this update a shot:
http://dl.dropbox.com/u/55284551/GauVeldt_Ease.zip
B
28
S
5
G
1
Posts: 30
Reputation: 1,889

Post » Sat Feb 11, 2012 4:07 am



It works beautifully!

I used a start of layout and for each object event, and then set the origin points and destination points relative to their starting X and Y placements, and lo and behold...

I'd post a .capx but it uses a number of extra plugins. I was playing around with a little Mario game (as I oft do to learn how to do things) and wanted to make the bump effect that occurs on a block when you jump into it. This Ease behavior does the trick so well. I'm excited to incorporate it into my real game!

Thanks a ton again for this!
B
58
S
20
G
7
Posts: 305
Reputation: 8,804

Post » Sat Feb 11, 2012 6:26 am

[QUOTE=TL22]

It works beautifully!

I used a start of layout and for each object event, and then set the origin points and destination points relative to their starting X and Y placements, and lo and behold...

I'd post a .capx but it uses a number of extra plugins. I was playing around with a little Mario game (as I oft do to learn how to do things) and wanted to make the bump effect that occurs on a block when you jump into it. This Ease behavior does the trick so well. I'm excited to incorporate it into my real game!

Thanks a ton again for this![/QUOTE]

Another way is to use an numerical instance variable as a waypoint index and use comparison conditions to decide what to set the points to based on the value of the instance variable. This works really well if you make it its own event using the function plugin and call it in any actions (on the object being eased) that need to update the waypoints since it eliminates duplication and the potential to forget to update one of the duplicated events whenever the waypoints were altered during design. You can use the endpoint events to increment the counter then call the endpoint change actions prior to retriggering the movement action.
GauVeldt2012-02-11 06:29:30
B
28
S
5
G
1
Posts: 30
Reputation: 1,889

Next

Return to Completed Addons

Who is online

Users browsing this forum: gamecorpstudio, X3M and 1 guest