Skip to content

rotating objects (need a bit of help)

I have a few levers that I am using to spin a placeable, it is working but I am having a hard time figuring out how the float is actually working. This script spins the placeable 360 degrees which is what I want, but it only works the first time I pull the lever. I would like it to spin 360 degrees every time I pull it.
//360 degree rotation
void main()
{
object oPC = GetLastUsedBy();
object oTarget = GetObjectByTag(GetTag(OBJECT_SELF)+ "_Target");

float x = GetFacing(oTarget);

x = 360.0;

SetObjectVisualTransform(oTarget, OBJECT_VISUAL_TRANSFORM_ROTATE_X, x, OBJECT_VISUAL_TRANSFORM_LERP_LINEAR, 6.0, TRUE);

PlaySound("as_cv_brickscrp1");
DelayCommand(0.50, PlaySound("as_cv_brickscrp1"));
DelayCommand(1.0, PlaySound("as_cv_brickscrp1"));
DelayCommand(1.5, PlaySound("as_cv_brickscrp1"));
DelayCommand(2.0, PlaySound("as_cv_brickscrp1"));
DelayCommand(2.5, PlaySound("as_cv_brickscrp1"));
DelayCommand(3.0, PlaySound("as_cv_brickscrp1"));
DelayCommand(3.5, PlaySound("as_cv_brickscrp1"));
DelayCommand(4.0, PlaySound("as_cv_brickscrp1"));
DelayCommand(4.5, PlaySound("as_cv_brickscrp1"));
DelayCommand(5.0, PlaySound("as_cv_brickscrp1"));
DelayCommand(5.5, PlaySound("as_cv_brickscrp1"));

}

I need one that spins 90 degrees counter clockwise another 90 degrees clockwise, and one that spins 180 degrees clockwise. setting x = 90 or - 90 does provide results, just not the desired results.

I need some help!

Comments

  • TarotRedhandTarotRedhand Member Posts: 1,481
    Your problem is that SetObjectVisualTransform() rotates by an absolute amount. So if you tell it to rotate something by 360 degrees and you previously rotated it by 360 degrees nothing will happen. Not only that. If you tell SetObjectVisualTransform() to rotate 720 degrees to get around this and you have LERP enabled it will rotate your object completely around twice in the same amount of time as for 360 degrees. FWIW, I only discovered this when I created my Animated Starry Sky (Placeable & Script) for the

    Custom Content Challenge - January 2022 : Dual Themes (Once Upon a Time & Skyboxes).

    TR
  • QuilistanQuilistan Member Posts: 186
    so there is no way to rotate an object only 90 degrees each activation?
  • meaglynmeaglyn Member Posts: 151
    SetFacing() should work I'd think.
  • ProlericProleric Member Posts: 1,316
    edited March 2022
    SetFacing works fine (with the subtle difference that it's not merely the appearance that rotates - it turns the the entire model, including use nodes etc).

    SetObjectVisualTransform can be reset by repeating the previous command with a value and time of zero. So, rotate 360, wait, rotate 0 then immediately rotate 360 again.

    In my tests, reset followed by transform happens so fast that you don't see the reset - which is obviously not an issue with 360 rotation in any case.

    IIRC the reset is independent for each type of transform, so, for example, resetting the X rotation does not cancel a Z translation.
  • QuilistanQuilistan Member Posts: 186
    How do I get SetFacing() to rotate smoothly?

    It seems to just jump to the new position.

    I am trying to have the Stone Skull head rotate in the middle of a room after a lever is pulled. This along with the grinding stone sound has a nice mechanical affect. A certain pattern of rotation will hopefully unlock a door.
  • NeverwinterWightsNeverwinterWights Member Posts: 339
    edited March 2022
    So far all seems to be working in testing:
    void Clockwise360(object oObject, float fLurpDuration)
    {
        float fCurrentTransform = GetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X);
        SetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X, fCurrentTransform - 360.0, OBJECT_VISUAL_TRANSFORM_LERP_LINEAR, fLurpDuration, TRUE);
    }
    
    void CounterClockwise360(object oObject, float fLurpDuration)
    {
        float fCurrentTransform = GetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X);
        SetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X, fCurrentTransform + 360.0, OBJECT_VISUAL_TRANSFORM_LERP_LINEAR, fLurpDuration, TRUE);
    }
    
    void Clockwise180(object oObject, float fLurpDuration)
    {
        float fCurrentTransform = GetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X);
        SetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X, fCurrentTransform - 180.0, OBJECT_VISUAL_TRANSFORM_LERP_LINEAR, fLurpDuration, TRUE);
    }
    
    void CounterClockwise180(object oObject, float fLurpDuration)
    {
        float fCurrentTransform = GetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X);
        SetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X, fCurrentTransform + 180.0, OBJECT_VISUAL_TRANSFORM_LERP_LINEAR, fLurpDuration, TRUE);
    }
    
    void Clockwise90(object oObject, float fLurpDuration)
    {
        float fCurrentTransform = GetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X);
        SetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X, fCurrentTransform - 90.0, OBJECT_VISUAL_TRANSFORM_LERP_LINEAR, fLurpDuration, TRUE);
    }
    
    void CounterClockwise90(object oObject, float fLurpDuration)
    {
        float fCurrentTransform = GetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X);
        SetObjectVisualTransform(oObject, OBJECT_VISUAL_TRANSFORM_ROTATE_X, fCurrentTransform + 90.0, OBJECT_VISUAL_TRANSFORM_LERP_LINEAR, fLurpDuration, TRUE);
    }
    
    void main()
    {
        object oPC = GetLastUsedBy();
        object oTarget = OBJECT_SELF;//change this back to tag of target
    
        SetUseableFlag(OBJECT_SELF, FALSE);
    
        PlaySound("as_cv_brickscrp1");
        DelayCommand(0.50, PlaySound("as_cv_brickscrp1"));
        DelayCommand(1.0, PlaySound("as_cv_brickscrp1"));
        DelayCommand(1.5, PlaySound("as_cv_brickscrp1"));
        DelayCommand(2.0, PlaySound("as_cv_brickscrp1"));
        DelayCommand(2.5, PlaySound("as_cv_brickscrp1"));
        DelayCommand(3.0, PlaySound("as_cv_brickscrp1"));
        DelayCommand(3.5, PlaySound("as_cv_brickscrp1"));
        DelayCommand(4.0, PlaySound("as_cv_brickscrp1"));
        DelayCommand(4.5, PlaySound("as_cv_brickscrp1"));
        DelayCommand(5.0, PlaySound("as_cv_brickscrp1"));
        DelayCommand(5.5, PlaySound("as_cv_brickscrp1"));
    
        Clockwise180(oTarget, 6.0);
    
        DelayCommand(6.1, SetUseableFlag(OBJECT_SELF, TRUE));
    }
    

    Hope it helps.
    Post edited by NeverwinterWights on
  • ProlericProleric Member Posts: 1,316
    Quilistan wrote: »
    How do I get SetFacing() to rotate smoothly? ...
    The best way would be to use SetObjectVisualTransform, with either the reset method I proposed, or the GetObjectVisualTransform method proposed by @NeverwinterWights, both of which allow the action to be repeated as often as you like.

    If you have to use SetFacing(), use delays to rotate it in small angular steps - but that will never be as smooth.
  • QuilistanQuilistan Member Posts: 186
    Awesome! Thank you all.

    I used NeverwinterWights script and then set some variables on the object with a small amount of math and if statements to keep track of the direction.

    if the face is facing a door, the clockwise 360 spin unlocks and opens it. The counter clockwise 360 closes and locks it.

    Only one door can be open at a time.

    Fairly simple puzzle really, but cool action in game.
Sign In or Register to comment.