Skip to content

Instantly share code, notes, and snippets.

@cgsdev0
Last active November 21, 2022 03:53
Show Gist options
  • Save cgsdev0/398ad77fbca0221196c3611790ac3781 to your computer and use it in GitHub Desktop.
Save cgsdev0/398ad77fbca0221196c3611790ac3781 to your computer and use it in GitHub Desktop.
camera control rotation
// Takes in a movement vector and moves the cursor
static void moveHelper(ALevelEditorPawn* t, FVector v) {
if (!t->cursorLocation.Z && v.Z < 0) v.Z = 0; // Min floor
// Adjust input vector for camera rotation
AController* controller = t->GetController();
if (controller) {
FRotator rot = controller->GetControlRotation();
UE_LOG(LogTemp, Warning, TEXT("Rotation: %d"), (int)rot.Yaw);
if (rot.Yaw > 45 && rot.Yaw <= 135) {
float temp = -v.Y;
v.Y = v.X;
v.X = temp;
}
if ((rot.Yaw > 135 && rot.Yaw <= 225)) {
v.X = -v.X;
v.Y = -v.Y;
}
if (rot.Yaw > 225 && rot.Yaw <= 315) {
float temp = v.Y;
v.Y = -v.X;
v.X = temp;
}
}
t->cursorLocation += v * gridSize;
// RPC call for replication
t->Move(t->cursorLocation, t->selectionSize);
}
// Input mappings
void ALevelEditorPawn::MoveForward() { moveHelper(this, { 1, 0, 0 }); }
void ALevelEditorPawn::MoveBackward() { moveHelper(this, {-1, 0, 0 }); }
void ALevelEditorPawn::MoveRight() { moveHelper(this, { 0, 1, 0 }); }
void ALevelEditorPawn::MoveLeft() { moveHelper(this, { 0, -1, 0 }); }
void ALevelEditorPawn::MoveUp() { moveHelper(this, { 0, 0, 0.5}); }
void ALevelEditorPawn::MoveDown() { moveHelper(this, { 0, 0, -0.5}); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment