rotate script

Gurtag

Active member
hey guys is there a script that declaring it once rotate very frame on the animation? i have a large animation i want every frame to rotate to simulate an spining rock but dont want to pasting drawmethod command in every frame if i can avoid it... if get the value wrong or just dont like it would have to go over all the frames again...
 
hey guys is there a script that declaring it once rotate very frame on the animation? i have a large animation i want every frame to rotate to simulate an spining rock but dont want to pasting drawmethod command in every frame if i can avoid it... if get the value wrong or just dont like it would have to go over all the frames again...

Save this in your script folder. You can use whatever filename you like, but this example assumes dc_spin_main.c.

C:
void dc_spin(int delay) {
    if(typeof(delay) != openborconstant("VT_INTGER")) {
        log("\n ERROR dc_spin(" + delay + ") - Missing or invalid parameter.");   
        return;
    }
    
    void acting_entity = getlocalvar("self");

    // Zero, NULL(), or a negative delay switches the effect off.
    if (!delay || delay < 0) {
        setentityvar(acting_entity, "dc_spin_delay", 0);
        setentityvar(acting_entity, "dc_spin_remaining", 0);

        changedrawmethod(acting_entity, "rotate", 0);
        changedrawmethod(acting_entity, "enabled", 0);
        return;
    }

    // Restart the countdown only when the delay changes.
    // Repeating the same command during an animation loop
    // preserves both the countdown and the current angle.
    if (getentityvar(acting_entity, "dc_spin_delay") != delay) {
        setentityvar(acting_entity, "dc_spin_remaining", delay);
    }

    setentityvar(acting_entity, "dc_spin_delay", delay);
    changedrawmethod(acting_entity, "enabled", 1);

}

void dc_spin_sentinel()    {

    void acting_entity = getlocalvar("self");
    int delay = getentityvar(acting_entity, "dc_spin_delay");
    int remaining;
    int angle;

    // Unset or zero means this entity is not spinning.
    if (!delay)    {
        return;
    }

    remaining = getentityvar(acting_entity, "dc_spin_remaining") - 1;

    if (remaining <= 0)    {
        
        // Advance two degrees whenever the countdown expires.
        angle = (getdrawmethod(acting_entity, "rotate") + 2) % 360;
        changedrawmethod(acting_entity, "rotate", angle);

        remaining = delay;
    }

    setentityvar(acting_entity, "dc_spin_remaining", remaining);
}

In your entity's update script, import it and run the sentinel:

C:
#import "data/scripts/dc_spin_main.c"

void main() {
    dc_spin_sentinel();
}

If your update script already has a main() function, put dc_spin_sentinel(); inside the existing function.

In your animation script, you only need the import:

C:
#import "data/scripts/dc_spin_main.c"

Make sure you enable your animation and update scripts in the model sheet:

Code:
script data/scripts/your_update.c
animationscript data/scripts/your_animation.c

Now you're good to go. Call dc_spin with the delay you want between rotation steps. Use positive whole numbers:
  • 1 rotates two degrees every entity update.
  • 2 rotates two degrees every second entity update.
  • 4 rotates two degrees every fourth entity update.
  • 0 or NULL() turns the effect off, resets its stored rotation, and returns drawing control to the animation's frame settings.
For example, start spinning quickly, slow it down on a later frame, then turn it off:

Code:
@cmd dc_spin 1
frame data/chars/rock/rock_01.png

frame data/chars/rock/rock_02.png

@cmd dc_spin 4
frame data/chars/rock/rock_03.png

frame data/chars/rock/rock_04.png

@cmd dc_spin 0
frame data/chars/rock/rock_05.png

You can also use this to turn it off:

Code:
@cmd dc_spin NULL()

Place each command immediately before the frame where you want the change. The selected speed stays in effect across frames and animation changes until you change it or switch it off.

HTH,
DC
 
Back
Top Bottom