0
Planned

Animate float variable how to scale object over time

eagleeyez 5 months ago in Game Creator updated by Marti (Lead Developer) 3 months ago 8

Animate float variable how to scale object over time


Example I use the reducer potion on a player and instead of it going from big to small immediately it should scale down over time like a few seconds.


Is there something like animate float over time and if not could you make an action for this?

Unity version:
2019.3.0f3
Game Creator version:
1.1.3

This is what Animate float does in Playmaker. You can use it from anything like rotate, scale and position.

Ok, I did it like this and I just have to make a custom action out of it

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ScaleOverTime : MonoBehaviour
{
    public float targetScale =0.1f;
    public float growFactor = 5f;
    public float waitTime = 0.02f;
    

    // Press S to shrink or grow depending on your targetScale settings
    // in the editor 

    void Start()
    {
        Debug.Log("Started");
    }
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.S))
        {
            if (targetScale > transform.localScale.x)
                StartCoroutine(GrowMe());
            else if (targetScale < transform.localScale.x)
                StartCoroutine(ShrinkMe());
        }
    }

    IEnumerator GrowMe()
    {
        while (true) 
        {
            while (targetScale > transform.localScale.x)
            {
                transform.localScale += new Vector3(1, 1, 1) * Time.deltaTime * growFactor;
                yield return null;
            }
            yield return new WaitForSeconds(waitTime);
        }
    }
    IEnumerator ShrinkMe()
    {
        while (targetScale < transform.localScale.x)
        {
           transform.localScale -= new Vector3(1, 1, 1) * Time.deltaTime * growFactor;
            yield return null;
        }
        yield return new WaitForSeconds(waitTime);
    }
}

I found a nicer Playmaker action for this called curve float.

Maybe GC can do this already and I am just missing it.

If not, it's easy now to just make my own GC custom actions

+1
Planned

This looks interesting. I like the idea of allowing to interpolate different values. More so now that we have an easing library inside Game Creator.

I'll open a ticket and assess whether this makes sense. Game Creator usually is more on a "higher level of abstraction" than Playmaker, but this should be interesting enough to add.

Thanks!

+1


Ok, on the hub is also this one

Smoothly changes the current numeric variable value to another one over time

https://hub.gamecreator.io/content/item/wklrxyapcCqi4fWTiLj5

EDIT: is useful but not taking in gameobjects..

+1

Hi, I searched a long time how to do that but i think ther is a way to do that with GC.
First I was making a condition, "is myVar less than 20"

--> Then

i add+1 to myVar

i restart action

--> Else

i substract-50 to myVar

the problem is that the restart action continue infinitly and never answer the condition again... bouhouhou   :-(

BUT there is a "call condition" that exist in GC and you can put it  inside an action.

And it works!!!

You can than make any object grow or move overtime.


Nice! Yeah this seems to be a valid solution. The only problem I see is that it depends on the frame-rate. I'd recommend adding a "Wait" action before any action (something like 0.1 seconds) so it runs at the same speed on all computers.