Increase actor size smoothly

I've got an actor's width constrained to an attribute that goes up or down by different increments. At small increments, the actor's size increases relatively smoothly, but at great numbers it begins to get jerky.

The attribute that controls the width is modified by touch (when touch is pressed, the attribute goes up using an every X timer and change attribute behaviour, when it's released it goes down).

I can't use interpolates here because they would get interrupted when touch is pressed or released.

Can anyone think of a way to make the actor's width change more smoothly (easing through the increments)?

I've attached a demo of how the actor's width is currently being controlled (which if nothing else is a nice example of how to increase an attribute by a greater amount the longer mouse is pressed).

https://www.dropbox.com/sh/mcrdyuhw9wwzs5s/AABIlqHObPBdPXcVE7MZE9ila?dl=0

Comments

  • SocksSocks London, UK.Member Posts: 12,822

    @imjustmike said:
    I've got an actor's width constrained to an attribute that goes up or down by different increments.

    I can see (from looking at your project) how the width grows by differing amounts ?

  • SocksSocks London, UK.Member Posts: 12,822
    edited June 2016

    This is smooth:

    When mouse button is down
    --When width < 350
    ----Constrain width to self width +(width / 25)
    Otherwise
    --When width > 100
    ----Constrain width to self width - 5

  • imjustmikeimjustmike Member Posts: 450

    @Socks Thank you very much.

    Out of interest, why is having the width increase directly in the constrain smoother than constraining to an attribute that is modified?

    I've attached the gs file here in case anyone else needs to use this in the future:
    https://www.dropbox.com/sh/mcrdyuhw9wwzs5s/AABIlqHObPBdPXcVE7MZE9ila?dl=0

  • imjustmikeimjustmike Member Posts: 450

    Also, after playing around with it for a bit longer I've come to realise that it's not quite what I'm looking for. Whilst I want the decrease in width to be steady, I want the increase to be almost exponential. But I also always want the increase to start slow and build. So if I touch and release, the 'growth rate' is reset. That's why I was using two attributes to control it, including a multiplier that's reset when touch is released.

    Very easy fix though!

    I updated the same file - can see the difference by repeatedly holding down and releasing the mouse button. The third actor is a nice smooth increase, that increases width slowly when the mouse is first pressed and increases over time. Perfect.

  • ka822ka822 Member, PRO Posts: 40

    How about the loop function? I think this can work similar to interpolate if you have the numbers right.

  • imjustmikeimjustmike Member Posts: 450

    So whilst the increase in size is perfectly smooth now, it comes to a sudden stop when it reaches a certain size. Ideally what I'd want to happen is for it to smoothly stop increasing in size, then start decreasing.

    A good example of the effect would be when a character jumps by increasing the y velocity against accelerative rules for gravity - the character will jump up, start to slow down then start falling.

    Obviously I can't use accelerate. I've been trying to mess around with interpolates, and timers (default ones and custom ones) and I can get it work.

    @ka822 Do you know if loops would be the right solution? I've had a play but can't seem to get it to work.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    So... it sounds like you want an actor to expand (when continuously pressed) to a maximum width.

    But the actor needs to expand exponentially until it reaches about 85 percent of its maximum width. Then it continues to expand, but more slowly, until it reaches its maximum width.

    Then, after it reaches its maximum width (and the player continues to press the actor), it will start to exponentially contract until it reaches some minimum width.

    But if the player (while the actor is expanding) stops pressing on the actor, the actor needs to slow its expansion and then start to exponentially contract until it reaches some minimum width.

    But if the player keeps pressing on the actor through its expansion phase, and then through its contraction phase -- and then stops pressing in the middle of the contraction phase, does the actor simply continue its exponential contraction until it reaches some minimum width?

    Whew!?!

    Are there any other specifications about this specific mechanic that also need to be spelled out?

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    edited June 2016

    @imjustmike said:
    A good example of the effect would be when a character jumps by increasing the y velocity against accelerative rules for gravity - the character will jump up, start to slow down then start falling.

    Obviously I can't use accelerate.

    Sure you can!
    Just set the actor's width to another (jumping) actor's height. Here is an example:

  • imjustmikeimjustmike Member Posts: 450

    @RThurman said:

    Obviously I can't use accelerate.

    Sure you can!
    Just set the actor's width to another (jumping) actor's height. Here is an example:

    So that's EXACTLY the effect that I wanted to create, with a maximum jump height that as you point out in the above post would slow down as you approach it, probably starting at 85%.

    Even if it was possible to set that max jump height, is there a way to replicate the effect with attributes and a formula? Mostly because I just want to know how it's down, and a small part of me doesn't want a hidden actor doing the leg work as that feels like cheating for some reason!

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    It might feel like cheating at first. But you will get used to it!

  • imjustmikeimjustmike Member Posts: 450

    @RThurman said:
    It might feel like cheating at first. But you will get used to it!

    Ha! You're probably right. Only issue is there are about a dozen actors that I want to display this behaviour and all with slightly different parameters so having all those hidden jumping actors in the background doesn't feel like an elegant solution.

  • imjustmikeimjustmike Member Posts: 450

    Also, thinking about it - I want this effect to come into effect both at the actor's maximum height, and the minimum. Currently it reaches a hard stop when the actor hits the 'ground'.

    Annoyingly it's incredibly easy to create the effect with a combination of interpolate (with ease out) and timers. But I need to be able to interrupt the height change, which you can't do with interpolates.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    @imjustmike said:
    Also, thinking about it - I want this effect to come into effect both at the actor's maximum height, and the minimum. Currently it reaches a hard stop when the actor hits the 'ground'.

    OK -- that makes it easier, since you don't have to clip off the bottom.

    In that case, the expansion and contraction motion is really a sine-wave. Here is an example:

  • imjustmikeimjustmike Member Posts: 450

    @RThurman Interesting, I'm actually using something very similar on other actors in the project, but your implementation is a lot more smart and customisable. The one thing I struggled with was setting a maximum height for it to stop at. Currently, holding down will repeat the cos wave. What I'm ultimately after is 3 features:

    1. Increase in size almost exponentially (longer mouse is down,the quicker it grows)
    2. When mouse is released, don't stop grow immediately but slow to a stop before shrinking back to minimum.
    3. For there to be a minimum and maximum height, again that when reached isn't a hard stop, but a gradual decrease in growth.

    I'm creating a game whereby you have to grab certain things, the actor has it's x position locked so when it increases in size it only does it one way, like an arm extending to reach something. I'm trying to make it a little harder for the player - at the moment the arm extends and reaches a hard stop, so it's easy for the player to know where exactly where the arm will be - by introducing an easing effect hopefully it'll be more of a challenge. I think that makes sense...?

    An old prototype is here: https://www.dropbox.com/sh/dqn5mia1oi7jlgk/AAC7xpCIIQdse1Mft68uAWKka?dl=0

    All this just to make a game marginally harder....!

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    OK -- I guess I had a poor idea of what you were after. The prototype was extremely helpful.

    I think you are after a spring mass. (More like a pneumatic device.)

    Here is one way to make a damped spring (in two states).

  • imjustmikeimjustmike Member Posts: 450

    Thanks for this @RThurman - plenty in there to think about. I'm going to explore ways to not use interpolate - the game I'm working on relies on speedy clicking and precision, and interpolates don't perform the best under those circumstances

    Thanks for all your help!

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    You are welcome!

    The real workhorse isn't the interpolate behaviors -- but rather the negative control feedback loop (as given in the Hooke's law equation).

    The interpolate behaviors were just thrown in there to give the feel of sloppiness that you wanted. That is, when the user changes from mouse down, to mouse up, you wanted the actor to travel just a little further (and slow down) before it reverses course. You can speed up or slow down the interpolates until it gives just the right feel of sloppiness. Or you can just replace them with change attribute behaviors and they will reverse course immediately.

  • imjustmikeimjustmike Member Posts: 450

    @RThurman I wish I paid more attention in physics class as a kid. I vaguely remember playing around with elastic bands but that's pretty much the extent of my memory of Hooke's Law!

    Thanks for your help on this :)

Sign In or Register to comment.