Download

Issues with actor not rotating correctly

Hi,

I’m having a problem with my character not rotating when he goes around a corner in game.

		if (Actor1Position.X <= -900 && ActorCount == 4 && GetCurrentState() != ETypingRunPlayState::EGameOver && GetCurrentState() != ETypingRunPlayState::EWordRequired)
		{
			FRotator CharacterRotation = TypingRunCharacter->GetActorRotation();

			if (bTurnLeft == false)
			{
				turnWait += 1;
				if (bRotated == false)
				{
					SetCurrentState(ETypingRunPlayState::ERotateRight);
					CharacterRotation.Yaw += 90 * DeltaSeconds;
					TypingRunCharacter->SetActorRotation(CharacterRotation);
					bRotated = true;
					GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Rotate right"));
				}	
			}
			else
			{	
				turnWait += 1;
				if (bRotated == false)
				{
					SetCurrentState(ETypingRunPlayState::ERotateLeft);
					CharacterRotation.Yaw -= 90 * DeltaSeconds;
					TypingRunCharacter->SetActorRotation(CharacterRotation);
					bRotated = true;
					GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Rotate left"));
				}

			}

			if (turnWait >= 105)
			{
				turnWait = 0;
				PlatformMover();

				if (bTurnLeft == false)
				{
					CharacterRotation.Yaw -= 90 * DeltaSeconds;
					TypingRunCharacter->SetActorRotation(CharacterRotation);
				}
				else
				{
					CharacterRotation.Yaw += 90 * DeltaSeconds;
					TypingRunCharacter->SetActorRotation(CharacterRotation);
				}
			bRotated = false;
			}

Any ideas? It’s definitely running the other statements in the Ifs so I don’t see why it won’t rotate my character…

Link to the formatted code is here:

https://answers.unrealengine.com/questions/210671/actor-not-rotatingrunning-sideways.html

I’m needing a solution to this issue pretty urgently so any help would be greatly appreciated!

Your “90” there should be “90.0f”. I don’t remember if there is any implicit casts done in int to float (whether the int constant is converted to a float, or if the float is floored to an int). If it’s the later, then I could easily see you getting 0 for the rotation. Other than that, just toss in a break point and see what the code is doing.

Sorry for the big delay in getting back about this. I have tried that but it does not seem to resolve the issue.

It’s no longer mega urgent as I have managed to *kind of * hide the problem but I would still like it to be fixed.

Any idea guys?