I’m trying to find a simple way to move my character in the game using WASD and mouse controls. The problem is, I set it up similar to the way the FPS tutorial shows, however this means that if I want to fly the camera around off the ground it is not possible. So I’ve turned off activating character movement activation which means I’ve lost my WASD controls as no controller is now found.
The old code:
if ((Controller != NULL) && (Value != 0.0f))
// find out which way is forward
FRotator Rotation = Controller->GetControlRotation();
// add movement in that direction
const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
Now I need a way to do this, but without needing the character movement to be active:
if (Value != 0.0f)
SetActorRelativeLocation(FVector(GetActorLocation().X+ 5.f * Value, GetActorLocation().Y, GetActorLocation().Z));
Similar to that, but obviously that moves in a global axis XYZ, I need it relative to the actors direction and I’m not sure if there’s something built in for this or not?
Always find some answer when you keep messing around with the code… I’ve now got it replicating my character movement but still need it to move in the direction that the camera faces (like a flying free cam), as at the moment I have the left and right movement, but can’t seem to get it to move in the actual camera direction.
Code so far:
if (Value != 0.0f)
FVector Direction = GetActorForwardVector();
SetActorRelativeLocation(FVector(GetActorLocation().X + 10.f * Value * Direction.X, GetActorLocation().Y + 10.f * Value * Direction.Y,
GetActorLocation().Z + 10.f * Value * Direction.Z));
I’ve attempted to add this with the code above but it doesn’t seem to do anything? I think it has something to do with the fact that I have a MoveForward function, which when W/S is pressed moves forward/back down the X axis only (but not in the direction of the camera) and A/D moves down the Y axis, perpendicular the the camera’s facing. However, I need it to move ‘into’ or down the direction of the cameras facing vector on W/S, rather then just down the X axis as my Z seems to stay constant.