Essentially what I want to do is have a character be able to turn from a person to a vehicle, and back with the press of a button, wherever they are, and play an animation in between. But I’m having difficulty figuring it out, as most tutorials is getting a player to possess an already existing car.
There are two bits:
- Doing the animation
- Changing how the character is controlled
First, the animation has to be built in a modeling tool such as Maya or Blender. You build the character, including its skeleton, and morph targets, and build the transforming animation. You probably also build a variety of idle/walk/run/turn animations, because the skeleton won’t match the Unreal standard skeleton and thus you’ll need custom animations in your animation blueprint.
Then you export all those bits to FBX using the recommended settings, and import into UE, and build the appropriate assets for skeleton/skeletal-mesh/blend target/animation/physicsasset/animation blueprints.
Once you have this, it should be simple to trigger the “play animation ‘turn to vehicle’” and “play animation ‘turn to human’” as part of a normal animation blueprint state machine. But the modeling work is pretty intricate – here’s hoping you enjoy doing this, or know someone who does
Second, the “behave like a character, and then like a car,” can be done in at least two ways.
The first is to build a custom Pawn class (not a Character at all) with a custom Movement Component, which implements both “walking movement” and “driving movement,” with different behavior based on what mode it’s in. This is a lot of work, because you have to emulate all of the character behavior you get for free from a Character, and you have to emulate all of the vehicle behavior you get for free from a Wheeled Vehicle. But you have total freedom! If you also want airplanes, helicopters, and all the rest, well, you’re in control!
This requires a lot of understanding about physical simulation and kinematics. Here’s hoping you enjoy this work, or know someone who does!
The second is to cheat. You use a Character as the controlled Pawn, and play the animation to turn into a car. But, once the animation is done, you spawn a Wheeled Vehicle pawn, hide/destroy the Character pawn, and possess the Vehicle pawn, placing it in the same spot the Character was. Assuming all assets are pre-loaded, you should be able to do this in a single tick without too much of a glitch. The PlayerController will then provide its input to the new pawn. Note that things you might do that are Character-specific (such as “Jump”) and vehicle specific (such as “E-Brake”) would have to know whether you’re in character or vehicle mode, in the player controller, to forward those inputs appropriately.
The benefit of the second method is that you get to re-use the Character and Vehicle work that’s already done, but you instead have to deal with the transition switcharoo, and you have to cast to the right class in the Player Controller based on which mode you’re in, to call the right functions/methods.
Well, to be honest I’ve not really done any of this before, so… good starting point… But currently I’ve got a vehicle pawn and a character, but I need to find a way to make a regular pawn behave like a character. I’m just seriously not sure how to get it to switch between the two, or how to actually do the switching of the second method, as I have a character, and a vehicle pawn, just struggling with how to switch them out…
You need to do this from a PlayerController.
When you transform, you can create the other kind of pawn (vehicle), and call Possess on it (on the server/authoritative instance – but if you’re single player, that’s automatic)
If you haven’t used the PlayerController for your player actions yet, I highly recommend moving input management out of the Pawn/Character, and into the PlayerController, as it gives you a more “permanent” place to receive and control things, because otherwise, if the “pause menu button” lives in the Character, and you switch it out for a Vehicle, then you’d have to re-implement that function…
Add a Boolean and name it “is car”
When you press W you ask with a Branch - “is car says true or false?”
And depending on answer you either walk and play animation of walking, if it should say yes - do driving instead of walking
And same rule for any other action