Forum rules - please read before posting.

Object: Transform action via script

Hi everyone

I'm trying to learn how to generate actions and action lists through scripts.

Related to this Object: Transform GUI action shown in this picture: https://imgur.com/a/KvT4pIy

My question is, how can I write the same "translate by" action in code?

I noticed there is AC.ActionTransform.CreateNew(). But I don't want to use a marker. Instead, I want to translate it by some Vector3 value. Is there a simple way to do this?

Comments

  • Welcome to the community, @antakasa.

    The CreateNew function can be used to generate an Action through script. Actions typically have multiple variants of this to allow for different parameters, but currently only the "Marker" variant you describe is available for ActionTransform.

    I will see about adding new variants in the next release - thanks for the suggestion.

    In the meantime, you can add the following to the bottom of the ActionTransform script (just beneath the existing CreateNew function) to give you the ability to create a "Translate By" Action:

    public static ActionTransform CreateNew_TranslateBy (Moveable objectToMove, Vector3 moveAmount, float transitionTime = 1f, MoveMethod moveMethod = MoveMethod.Smooth, AnimationCurve timeCurve = null, bool waitUntilFinish = false)
    {
        ActionTransform newAction = CreateNew<ActionTransform> ();
        newAction.linkedProp = objectToMove;
        newAction.transformType = TransformType.Translate;
        newAction.newVector = moveAmount;
        newAction.toBy = ToBy.By;
        newAction.transitionTime = transitionTime;
        newAction.moveMethod = moveMethod;
        newAction.timeCurve = timeCurve;
        newAction.willWait = waitUntilFinish;
        return newAction;
    }
    

    Creating such an Action would then be a case of calling:

    ActionTransform.CreateNew_TranslateBy (objectToMove, moveAmount, 2f, MoveMethod.Linear, null, true);
    

    If your Vector3 variable is taken from a component Variable, you'll need to extract that variable's value and pass it into the moveAmount parameter, e.g.:

    Vector3 moveAmount = GetComponent<Variables> ().GetVariable ("down").Vector3Value;
    

    More details on scripting Actions can be found in the Manual's "Generating ActionLists through script" chapter, as well as with the ScriptedActionListExample script file included in AC's package.

  • This works perfectly, many thanks to you Chris!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.