x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

AnswerHub Maintenance

Background maintenance is scheduled to occur between 9 - 11am EDT on Tuesday, May 21. Site operation may be slower than normal during this time and a brief interruption in operation may be observed

Custom Pawn Turn rate is too fast.

Alright, so I'm trying to make a pawn character that turns slower the faster you're going. For my control scheme I consider the direction the player inputs is the way they want to go, so say that you want to go southwest and the character is going north you would press the controls southwest and wait for your character to turn to match.

The problem: is that my pawn seems to be rotating WAY TOO FAST, to the point that it could just be doing random rotations and is practically a blur.

Here is the code that "throttles" the difference in direction to my max turning speed:

 if (!TurningAmount.IsNearlyZero())
         {
             
 
             if (abs(TurningAmount.Yaw) <= 90)
             {
                 NewRotation.Yaw += .0001 * (TurningAmount.Yaw / 90);
             }
             else
             {
                 NewRotation.Yaw += .0001 * (1 - ((TurningAmount.Yaw - 90) / 90));
             }
 
             /*
             FString Result = FString::SanitizeFloat(NewRotation);
             GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, Result);
             */
 
             NewVelocity = NewRotation.RotateVector(NewVelocity);
         }


For clarity, TurningAmount is a FRotator set to represent the angle difference between the direction I want to go and the direction my pawn is currently going. It ranges for -180 to -180 with 0 being no difference in direction. I want it so my pawn rotates the fastest when the angle difference is a right angle or "90".

I haven't set up my turning speed value yet cause I wanted to get the code working on a normal level first. For now I've been representing that as the .0001. It was originally a 1 but I tried making it smaller thinking I had just set the code to rotate too fast.

OH, and I almost forgot: the code above is in my tick function and "should" be already controlled by delta seconds. I've been coding this in stages and it's worked perfectly until I added this rotation code.

Thank you for any and all help.

Product Version: UE 4.21
Tags:
more ▼

asked Mar 31 '19 at 04:56 AM in C++ Programming

avatar image

Hyperon_Ion
3 1 1 1

avatar image Hyperon_Ion Mar 31 '19 at 02:51 PM

Bit of an update: I've managed to stop it from spinning like a top by normalizing a lot of the rotations I'm using, but I still have a problem.

At first when I run the game it seems to work fine, but after a few moments the pawn "hitches" on something and then it starts sort of vibrating and goes in the wrong direction.

I'm genuinely stumped by this.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Ok, I finally got fed up and just rewrote the code from scratch.

 if (!TurningAmount.IsNearlyZero())
         {
             if (abs(TurningAmount.Yaw) <= 90)
             {
                 NewRotation.Yaw = TurningAmount.Yaw;
             }
             else
             {
                 NewRotation.Yaw = 180 - TurningAmount.Yaw;
             }
 
             NewRotation.Normalize();
             NewRotation.Yaw /= 90;
 
             NewVelocity = NewRotation.RotateVector(NewVelocity);
         }

Basically I was forced to move my math out of the if/else statement and have that focus on just figuring out how much my controller is turning.

Hope someone learns from this, cause I'm not sure if I have...

more ▼

answered Apr 06 '19 at 05:51 PM

avatar image

Hyperon_Ion
3 1 1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question