Issues with SetActorRotation

Hi all,

So, what I want to do is rotate my character 90 degrees.

I have the below code:

CharacterRotation.Yaw += 90.0f;
TypingRunCharacter->SetActorRotation(CharacterRotation * DeltaSeconds);

It does not appear to do anything but if I take out “* DeltaSeconds”, the character rotates correctly but it breaks loads of other things (other actors in the scene have moved from where they should be etc.).

I have very similar code that rotates some platforms that I use in game and this seems to work with no issues so I don’t understand why the above code doesn’t work.

Anyone have an idea what’s going on?

Thanks!

I assume that what you want to do here is to smoothly rotate the TypingRunCharacter, so you should do that like this:



TypingRunCharacter->SetActorRotation(TypingRunCharacter->GetActorRotation() + FRotator(0.0f, 90.0f, 0.0f) * DeltaSeconds)); //The character will be smoothly rotating with a speed of 90 degrees per second

//You can also use AddActorWorldRotation


It seems you are scaling your entire rotation by DeltaSeconds, instead of just the velocity you want to apply. What you want to do is



Rotation = Rotation + (RotationRate *  TimeStep)


but what you’re doing instead is:



Rotation = (Rotation + RotationRate) * TimeStep


I hope you can figure it out from there. :slight_smile:

Thanks guys, I’ll give it a go when I get home from work tonight!

Okay so I’ve finally had time to try this out but it still seems to be causing issues so I’m guessing it has something to do with other parts of the code.

I have all these platforms that the character stands on in the game. These platforms are rotated as well as the character. If I choose not to rotate the character, they all line up fine like so:


If I do choose to rotate the character, they all go out of alignment like so:


It’s more pronounced on a slower PC.

The code I’m using to rotate the platforms:


	if (bTurnLeft == false)
	{
		ActorRotation.Yaw += 90.0f * DeltaSeconds;

		for (TActorIterator<ALevelGen> ActorItr(GetWorld()); ActorItr; ++ActorItr)
		{
			FVector ActorPosition2 = ActorItr->GetActorLocation();

			if (ActorPosition2.Y != 0)
			{
				if (MoveCount == 0)
				{
					ActorPosition2.X = 0;
					ActorPosition2.Y = 0;
					ActorItr->SetActorLocation(ActorPosition2);
					ActorItr->SetActorRotation(ActorRotation * DeltaSeconds);
					MoveCount += 1;
				}
				else if (MoveCount == 1)
				{
					ActorPosition2.X = 3180;
					ActorPosition2.Y = 0;
					ActorItr->SetActorLocation(ActorPosition2);
					ActorItr->SetActorRotation(ActorRotation * DeltaSeconds);
					MoveCount += 1;
				}
				else if (MoveCount == 2)
				{
					ActorPosition2.X = 6360;
					ActorPosition2.Y = 0;
					ActorItr->SetActorLocation(ActorPosition2);
					ActorItr->SetActorRotation(ActorRotation * DeltaSeconds);
					MoveCount = 0;

				}
			}

		}

	}

	else
	{
		ActorRotation.Yaw -= 90.0f * DeltaSeconds;

		for (TActorIterator<ALevelGen> ActorItr(GetWorld()); ActorItr; ++ActorItr)
		{
			FVector ActorPosition3 = ActorItr->GetActorLocation();

			if (ActorPosition3.Y != 0)
			{
				if (MoveCount == 0)
				{
					ActorPosition3.X = 0;
					ActorPosition3.Y = 0;
					ActorItr->SetActorLocation(ActorPosition3);
					ActorItr->SetActorRotation(ActorRotation * DeltaSeconds);
					MoveCount += 1;
				}
				else if (MoveCount == 1)
				{
					ActorPosition3.X = 3180;
					ActorPosition3.Y = 0;
					ActorItr->SetActorLocation(ActorPosition3);
					ActorItr->SetActorRotation(ActorRotation * DeltaSeconds);
					MoveCount += 1;
				}
				else if (MoveCount == 2)
				{
					ActorPosition3.X = 6360;
					ActorPosition3.Y = 0;
					ActorItr->SetActorLocation(ActorPosition3);
					ActorItr->SetActorRotation(ActorRotation * DeltaSeconds);
					MoveCount = 0;
				}

			}

Code I’m using to rotate the character:


		if (bTurnLeft == false)
			{
				turnWait += 1;
				if (bRotated == false)
				{
					TypingRunCharacter->SetActorRotation(TypingRunCharacter->GetActorRotation() + (FRotator(0.0f, 5000.0f, 0.0f) * DeltaSeconds));
				}	
			}
			else
			{	
				turnWait += 1;
				if (bRotated == false)
				{
					TypingRunCharacter->SetActorRotation(TypingRunCharacter->GetActorRotation() + (FRotator(0.0f,-5000.0f, 0.0f) * DeltaSeconds));

				}

These are both being called in the tick function.

I know there’s a few things I could tidy up in there but any idea what might be causing this issue?

Anyone got an idea of what it might be?