Character Rotation / Movement is Offset when Changing at Runtime?

I’m having trouble fixing one key issue with my character’s rotation in my project.

So currently I have a system where by you can switch character’s at run time using “1” key, and it will drop out the current character and replace it with a new one of the same class.

I’ve created a base character blueprint for this, and the characters that spawn in on begin play and when needed to be swapped using “1” are child blueprints of this class.

Assets

Now when initially spawning into the game, the character’s movement and rotation is perfectly fine, the issue is that when swapping this character for the next, if it is facing in any direction away from it’s initial spawn foward vector, all movement is now oriented differently.

It’s a bit hard to describe, but here’s a diagram of what I’m talking about:

As you can see allowing for input is fine, it’s just the direction is now altered to fit the new character’s forward facing direction rather than the world’s forward vector.

I’m suspicious about the character’s relative location when spawning into the world, but have no clue if this is the main issue at hand.

If this isn’t enough info that is needed then let me know and I’ll provide some more details about the project.

Any help would be greatly appreciated to fix this. Thanks

Can you show your spawn code?

Sure. So currently I have two blueprints that control the character’s spawning. I’ve got a custom player controller blueprint and a game mode blueprint.

To spawn a character (one of the two child actors), I’ve made a function (called “Spawn Player Character”), that will loop through an array of the child actors and selects which one to spawn based on a index parameter and where using transform data.

“Spawn Player Character Function” (inside of Custom Game Mode Blueprint):

To swap between players, I use the custom player controller blueprint to find the character in the scene that it’s currently possessing, compare it with the characters in the array (passed through as a reference from the game mode blueprint), and call an interface message to a “Swap Player” function that I’ve implemented back inside the game mode blueprint if the character’s ARE indeed different (also passing through the transform & index data that are needed to spawn in the correct place).

“Character Swap” Action Event (inside of Custom Player Controller):


This “Swap Player” interface function takes the passed through index and transform data and sends it to the “Spawn Player Character” function inside of the game mode blueprint (as seen in first image) that will spawn a new character (might seem like a waste, but it makes sense given what is next).

“Swap Player” Interface Function (inside of Custom Game Mode Blueprint):

“Spawn Player Character” Function (inside of Custom Game Mode Blueprint):

So I do also use the “Spawn Player Character” function at the start of the game when spawning the first character. To put it simply, I first spawn a series of empty pawns to recognise when & where a player should spawn, and carry out the exact same process as before, call an interface message to another interface function called “Spawn Player” (from inside of this empty pawn blueprint), pass through the data needed (index & transform data), and let the “Spawn Player Character” function spawn the character into the scene.

“Spawn Players” Action Event (inside of Empty Pawn Blueprint - to spawn first initial character):

“Spawn Player” Interface Function (inside of Custom Game Mode Blueprint):


Spawn Player (Game Mode).2

“Spawn Player Character” Function (inside of Custom Game Mode Blueprint)

But since this is only responsible for spawning the first character into the game, I’ve got no issues with character rotation / movement, so I don’t believe the problem lies here.

I found that swapping the characters when the player is facing the world’s forward facing direction causes no rotation issues, it just when it’s swapped once the character faces any other direction. All the inputs for movement are now local to the character’s forward facing direction rather than the world’s. That’s the best way I can describe the problem (along with the visual aid I linked in the previous post).

If there’s anything more specific that you want to look at, do let me know, I’ll try my best to find it. Thanks.

Just as a simple summary for this post, here is a summary of events that happens during the game:

  1. Spawning First Character:
    A). Spawn Empty Pawn’s into Scene
    B). Player presses “Enter” to Spawn First Character
    C). This calls Interface Message “Spawn Player” to Game Mode Blueprint.
    D). “Spawn Player” Interface Function uses “Spawn Player Character” function to spawn first player (at relevant empty pawn location).

  2. Swapping Characters (by pressing “1” Key).
    A). Player presses “1” key to swap their character.
    B). Player Controller Blueprint compares current character with array of available characters.
    C). If character’s are different, the player controller unpossess the current character.
    D). Player Controller calls interface message, “Swap Player” (to Game Mode Blueprint).
    E). “Swap Character” interface function passes through relevant data to “Spawn Player Character” function.
    F). “Spawn Player Character” function spawns the other character.
    G). Player Controller possess the newly spawned character.

Hopefully that’s a lot more staight-forward if the first post seemed a bit much :ok_hand:.

That’s absolutely layers and layers of ‘stuff’.

A few questions:

  1. Does the character still move correctly? ( ie, forward is their own forward ).

  2. Have you tried stripping it right down? ( if you just spawn the characters at different transforms, from a level BP, nothing else, do they work as expected? )

  3. I don’t know what else you’ve done in the controller. Have you been tinkering with the control rotation settings etc?

Yeah sorry about that, I tried to get in all the necessary info that I could. But to answer your questions.

  1. The character will always moves forward given their forward direction. The issue is that I want the character to always move forward based on the world’s forward vector and not their own. So when he spawns facing left for example, then forwards is still the world’s forward facing direction and not the character’s new forward direction. Kind of a muddled description I know, just let me know if that makes any sense.
  2. Spawning the characters with random transforms encounters the same problem. If it’s a random rotation then the character will move forward based on it’s forward facing direction and not the world’s.
  3. I haven’t experimented with the controller’s settings, although I have done so with the character blueprint. But I’ve reset them back to their defaults and the problem is still occuring.

1 and 2 seem to contradict each other. Is that right.

In fact, have you tried spawning at the location, but using SetControlRotation to accomodate the rotation ( rather than feeding it into the spawn )?

I have a suspicion and a debug I think you should try.

The Debug:
Try always spawning the rotation property of your characters to be some default vector. I’m assuming an Rotator that’s 0,0,0 should suffice. Then you can sus out a bit better what is causing your offset since you know exactly where it “Should” have ended up.

My suspicion is that you’re applying your rotations in an odd way. Remember that Actors don’t actually have a rotation - their Scene component carries out all of the transformations.

Mainly are you effecting the rotation of the actor or the rotation of the controller? How exactly is your rotation being applied to the scene components of the actors you wish to rotate.

So Rumzie, your recommendation is a possible solution. I’ve just tested it now by breaking the transform data into only the location and scale and setting the rotation of the character when spawned to 0. But I would like to have it so that it shouldn’t matter which direction the character is facing in order to move forward, backward, left or right relative to the world.
And ClockWorkOcean, spawning the character’s initially has a value of 0 for rotation, therefore not affecting movement, but when altering this rotation value, whether its from the initial spawn to swapping the characters at run time enouncters the same movement issue.