How can I get my pawn moving towards its forward direction
I'm trying to make a pawn that will move towards the forward direction whenever the player is pressing the input to do so. Currently I can make it move up and down the X axis, however whenever the player rotates the object using the mouse it will continue to only move along the X-Axis, rather than moving forwards towards the direction it is facing. I've posted the code I have below #include "PlayerCharacter.h" #include "Cplusplusfirsttry.h" #include "Camera/CameraComponent.h" #include "Components/InputComponent.h" #include "Components/StaticMeshComponent.h" #include "GameFramework/PlayerController.h" #include "Engine/LocalPlayer.h" #include "GameFramework/DefaultPawn.h" #include "GameFramework/SpringArmComponent.h"
Your problem is the combination of this line:
...with these lines:
You seem to be almost there, but your code doesn't appear to make use of your character's forward vector as intended. (Even though you store the forward vector in a variable, the variable isn't used!)
You should be able to get your code working to some extent by just incorporating your
But, even with that change, I wonder whether you shouldn't consider a slightly different (and simpler) approach.
If you haven't already, I suggest taking a look at the C++ code that is generated with the First Person template, specifically the Player Controller and Pawn classes. Even if you're not making a first-person game, the code examples from that template show how to neatly use inputs to call very small functions that handle movement in all directions and rotation of the pawn using the mouse. I think you might find it useful to adapt some of the simplicity of that template code for your character class. (Just a suggestion! Totally up to you.)
answered Jan 18 '19 at 04:49 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here