Announcement

Collapse
No announcement yet.

Using a slider to rotate an object

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Using a slider to rotate an object

    In my FrontEnd UI I have a Mesh that I am currently rotating via 3 buttons(Left, Right and Reset). The Mesh will rotate x degrees when the left button is pushed and -x degrees when the right button is pushed then will reset itself to the initial rotation when reset is pushed.

    I'd like to get that functionality into a slider instead. The slider I am using is set to Min = -100, max = 100 and value = 0. I also have it's 'liveDragging' set to true. With 0 being its initial rotation and -100 going a full 360 degrees to the left and 100 going 360 degrees to the right with it changing directions depending on which way I am dragging the slider.

    Any ideas how might I go about doing this?

    Here is my current button setup:
    AS
    Code:
    //Rotation buttons
    btnWeaponLeft.addEventListener("click", this, "DoWeaponLeft");
    btnWeaponLeft.focused = false;
    
    btnWeaponReset.addEventListener("click", this, "DoWeaponReset");
    btnWeaponReset.focused = false;
    
    btnWeaponRight.addEventListener("click", this, "DoWeaponRight");
    btnWeaponRight.focused = false;
    
    function DoWeaponLeft() {
    	ExternalInterface.call("WeaponRotateLeft");
    }
    
    function DoWeaponReset() {
    	
    	ExternalInterface.call("WeaponRotateReset");	
    }
    
    function DoWeaponRight() {
    	ExternalInterface.call("WeaponRotateRight");	
    }
    GFx UScript class
    Code:
    // CALLED FROM ACTIONSCRIPT
    function WeaponRotateLeft()
    {
        local rotator RotDecriment;
        RotDecriment = WeaponPlaceableComponent.Mesh.Rotation;
        RotDecriment.Yaw -= 4096;
        WeaponPlaceableComponent.Mesh.SetRotation(RotDecriment);
    
    }
    
    // CALLED FROM ACTIONSCRIPT
    function WeaponRotateRight()
    {
        local rotator RotIncriment;
        RotIncriment = WeaponPlaceableComponent.Mesh.Rotation;
        RotIncriment.Yaw += 4096;
        WeaponPlaceableComponent.Mesh.SetRotation(RotIncriment);
    
    }
    
    // CALLED FROM ACTIONSCRIPT
    function WeaponRotateReset()
    {
    	WeaponPlaceableComponent.Mesh.SetRotation(rot(0,0,0));
    
    }

    #2
    You'll just need to get slider.value and use that data to determine where your model should be facing.

    Also, the event to listen for on the slider is "change" in ActionScript. This shows it in action, where the slider ranges from 0 to 359, and snaps to one degree increments.

    ActionScript 2.0 Code


    Code:
    slider.liveDragging = true;
    slider.maximum = 359; // slider will range from 0 to 359 degrees
    
    slider.snapping = true;
    slider.snapInterval = 1; // slider will snap to one degree
    
    slider.addEventListener("change", this, "handleSliderChange");
    
    function handleSliderChange()
    {
        trace(slider.value);
        ExternalInterface.call("WeaponRotate", slider.value);
    }
    Your UnrealScript would need to be something like this:

    UnrealScript
    Code:
    function WeaponRotate(float yaw)
    {
        local rotator r;
    
        r = rot(0, 0, 0); // this value should be the original rotation of the 3D object
        r.Yaw = yaw * DegToUnrRot; // OR: yaw * 65536 / 360;
    
        if (WeaponPlaceableComponent.Mesh != none)
        {
            WeaponPlaceableComponent.Mesh.SetRotation(r);
        }
    }
    Finally, you MAY want to tell the slider what its initial value should be, based on the initial rotation of the 3D object when it is first loaded/spawned in:

    Code:
    var GFxClikWidget MySlider;
    
    event bool WidgetInitialized(name WidgetName, name WidgetPath, GFxObject Widget)
    {    
        switch(WidgetName)
        {                 
            case ('slider'):
    	    MySlider = GFxClikWidget(Widget);
    	    break;
            default:
                break;
        }
        return true;
    }
    
    
    // This is the important part
    
    function SetSliderValue()
    {
        local rotator objectRotation;
        objectRotation = WeaponPlaceableComponent.Mesh.Rotation;	
        MySlider.SetFloat("value", (objectRotation.Yaw * UnrRotToDeg));
    }
    
    defaultproperties
    {
    	WidgetBindings.Add((WidgetName="slider",WidgetClass=class'GFxClikWidget'))
    }

    Comment


      #3
      Thanks Matt... works like a charm!

      I multiplied yaw by 182.04 and I get roughly 360 degree rotation going from left to right on the slider.

      Code:
      function WeaponRotate(float yaw)
      {
          local rotator r;
      
          r = rot(0, 0, 0);
          r.Yaw = yaw * 182.04;
      
          WeaponPlaceableComponent.Mesh.SetRotation(r);
      }

      Comment


        #4
        Any insight as to what classes you were extending? I'm working on something similar and I'm not sure which GFx class you extended.

        Comment

        Working...
        X