How do I set absolute position input to character position, or main camera position?

Overview

I have a need to define the position of the main character through an absolute value set of widgets in the UI. How do I connect the absolute values for position (X, Y and Z) to drive the position of the main character in world space?

I’ve been researching the API and found multiple methods by which it would be possible to do this, but neither of the dev paths seem straight forward. So, what I’ve found so far is:

  • Instancing the PlayerCameraManager class
  • Creating a new “Code First Person (C++)” project

Instancing PlayerCameraManager

Pros:

  • I have control over very specific camera values: FOV, Location, Rotation, Aspect Ratio, Post Process Setting
  • Ability to add further functionality to the camera seems best here
  • It seems setting the “Location” and “Rotation” values allow for setting absolute values

Cons:

  • Can’t see how to connect an input to any of the attributes here
  • Complex structure: It seems that PlayerCameraManager contains: struct FCameraCacheEntry CameraCache ( which contains: float TimeStamp, and FMinimalViewInfo POV), and APlayerController* PCOwner
  • Unsure if controlling the Location attribute here

“Code First Person (C++)” Project

Pros:

  • Much easier access to controlling the player and therefore the camera via: UInputComponent->BindAction() or UInputComponent->BindAxis()

     void FirstPersonCPPProject::SetupPlayerInputComponent(class UInputComponent* inComp)
     {
         	// set up gameplay key bindings
         	check(inComp);
    
         	inComp->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
     
         	inComp->BindAction("Fire", IE_Pressed, this, &FirstPersonCPPProject::OnFire);
         	inComp->BindTouch(EInputEvent::IE_Pressed, this, &FirstPersonCPPProject::TouchStarted);
    
         	inComp->BindAxis("MoveForward", this, &FirstPersonCPPProject::MoveForward);
         	inComp->BindAxis("MoveRight", this, &FirstPersonCPPProject::MoveRight);
     
         	// We have 2 versions of the rotation bindings to handle different kinds of devices differently
         	// "turn" handles devices that provide an absolute delta, such as a mouse.
         	// "turnrate" is for devices that we choose to treat as a rate of change, such as an analog joystick
         	inComp->BindAxis("Turn", this, &APawn::AddControllerYawInput);
         	inComp->BindAxis("TurnRate", this, &FirstPersonCPPProject::TurnAtRate);
         	inComp->BindAxis("LookUp", this, &APawn::AddControllerPitchInput);
         	inComp->BindAxis("LookUpRate", this, &FirstPersonCPPProject::LookUpAtRate);
     }
    
  • Less complex entry point to begin making immediate changes

Cons:

  • Less control over camera parameters
  • No clear control for setting absolute camera position values. I think I would have to connect to an instance of “APawn” in order to set a new player controller (the tool that would take the GUI values and connect through the APawn to inComp->BindAxis (or inComp->BindAction). How this connection would happen though I have no clear idea yet. Furthermore, it seems that these controls, like APawn::AddMovementInput(), work in the method of moving on the current axis as defined by the view direction… so that converting absolute values to strength of movement on predefined axis would be difficult.

So… Any thoughts?

So,I’m looking at this function ACharacter::UpdateSimulatedPosition. I’ll look into this function and report back it’s ability to set absolute positions for the player in the game.

I found the answer…

AActor::SetActorLocation(FVector someVal)

This function on the player will allow for absolute positioning of the character.