Announcement

Collapse
No announcement yet.

Rotation "flipping" Problem

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

    Rotation "flipping" Problem

    Ok, I've got a reasonably complicated problem here, so bear with me. I'm trying to control a "thruster" attached to the bone structure of a vehicle. I'm taking a vector, scaling it to a float amount (you'll see what I mean) and then turning that into a rotator which is used to set the rotation of a bone. Details:

    First, I get the vector from the player inputs by adding values between -1 and 1 into a "target" vector. This is the percentage of the magnitude available to the finished vector. So .2 would be 20%. This is then fed to the "thruster." Like so:
    Code:
        if (Player is Pushing back)
        {
    	Target.x -= 1.0000000;
            // All the power for the thruster goes to back
        }
    
        if (Player is Pushing Down)
        {
    	Target.z += 1.0000000;
            // All the power for the thruster goes to down
            // Positive is effectively down, probably because of something 
            // screwed up later.  Keep readin'...
        }
    
        Thruster.DoThrust(Target);
    The thruster is attached with AttachToBone() to the main vehicle. Both of these commands work fine on their own, but when pressed together I get a strange angle.

    The Target vector is passed through this function, which is designed to get a "scaled" vector when two buttons are pressed. This way, if it should be pointing a little bit down and a lot back, it can do that.
    Code:
    function vector ScaleVector(vector InputV)
    {
        local vector ScaledV;
        local float InputLength;
    
        InputLength = VSize(InputV);
    
        if (InputLength > 1)
        {
    	ScaledV = InputV * MyVehicle(Owner).ThrustAvailable * (1/InputLength);
        }
        else if (InputLength <= 1)
        {
    	ScaledV = InputV * MyVehicle(Owner).ThrustAvailable;
        }
    
        Return ScaledV;
    }

    Pushing back and down together should get you an angle of about 45 degrees down and back. Instead, I get 45 degrees UP and back. If I flip the sign on the input for "down", the opposite happens. I get up when pressed by itself, and down and back when pressed with back.

    Here is how I'm using this vector, and I think my problem is in here somewhere:
    Code:
    function float DoThrust(vector InputV)
    {
        local vector ThrustV;
        local rotator ThrustR;
        local float ThrustPow;
    
        if (InputV != vect(0,0,0))   // As long as it shouldn't be idle...
        {
    	ThrustV = ScaleVector(InputV);
    	ThrustR = Normalize(Rotator(ThrustV));
    	ThrustPow = VSize(ThrustV);
    
    	// Set the Rotation
    	Owner.SetBoneRotation(AttachmentBone,ThrustR,1.0);
    	// Add the Power
    	Owner.KAddImpulse( ((vect(1,0,0) * ThrustPow) >> Rotation), Location);
        }
        else  // If there is no input...
        {
        }
    
        return ThrustPow;
    }
    As you can see, I'm trying to take the scaled vector and break it down into a rotator and a "thrust vector." The bone that the thruster is attached to is rotated by the rotator, and then the "thrust" is applied to the vehicle with a KAddImpulse. When those two inputs are combined, however, the angle of the thrust is NOT what would be expected.

    I know this is complicated, and thanks a ton if you read this far. Any ideas?

    #2
    ThrustR = Normalize(Rotator(ThrustV));


    i THINK this is your culprit. normalize returns a rotator between -32768 and 32768. meaning you lose direction (sign, +,-; -,-; +,+; -,+; etc) with this. instead, if you just need ThrustV to be a direction vector, then Rotator(Normal(ThrustV)) should be used. Rotator() might also return a unit vector on its own, im not 100% sure.

    Comment


      #3
      Ok, that solved some of the weirdities, but not everything. Thanks!

      I'm thinking at this point that it has something to do with the default bone rotations on the model. I had assumed they would be aligned with the root's rotation, but that doesn't appear to be the case, and it's causing strange results. Now to try to figure out how to align them.

      Comment


        #4
        make sure all your axis are aligned the same (x right, y foreward, z up) for all your bones in your mesh. sometimes 3d artists get careless and forget, or mirror the left side to the right to save time.

        Comment


          #5
          Is there a way to do this in UEd or am I going to have to figure out how to import a UT2K4 mesh into MayaPLE, if that's even possible, then do it there?

          Comment


            #6
            you can check the axis, but i dont think you can change them.

            Comment

            Working...
            X