I have been tweaking with the controls of the default FlyingExampleMap and this has led me to parent a C++ file to my pawn Blueprint because I want to be able to SetMousePosition, which is impossible with Blueprints alone.
I successfully parented C++ file with the function “SetMousePosition” to my BP but now whenever I start my game the camera starts in the middle of nowhere and I am unable to control the UFO. I even see my UFO fly lifelessly into the wall!
My two C++ files I used for parenting are as follows:
MyPlayerController7.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyPlayerController7.h"
#include "Fly1.h"
void AMyPlayerController7::SetMousePosition(float LocationX, float LocationY)
{
FViewport* v = CastChecked<ULocalPlayer>(this->Player)->ViewportClient->Viewport;
int intX = (int)LocationX;
int intY = (int)LocationY;
v->SetMouse(intX, intY);
}
MyPlayerController7.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "MyPlayerController7.generated.h"
/**
*
*/
UCLASS()
class FLY1_API AMyPlayerController7 : public APlayerController
{
GENERATED_BODY()
UFUNCTION(BlueprintCallable, Category = "Game|Player")
void SetMousePosition(float LocationX, float LocationY);
};
I want to be able to hold down a button and Pitch and Yaw the ship without having to continuously drag the mouse and pick it up again over and over. ‘Get Mouse X’ and ‘Get Mouse Y’ does not work in this regard and ‘Get Mouse Position’ is unreliable as well. I learned how to parent a C++ file to my Blueprint so that I can set the mouse location in order to facilitate this programming need so that if a button is held, the mouse can function to steer the ship more similarly to holding a joystick to one side or another.
I have been using blueprint for a while but have never had to dive into C++ until today. I also found my code from another on this forum so it may be outdated? Can anyone help me out please? Thanks.