Need help with replicating Yaw.

If this question is in the wrong forum or can be solved with Blueprints, please move it to the proper section.

Heyo UE Community,

I found this Project a couple hours ago for a Top Down Shooter ( GitHub - EdwardCoughlan/TwinStickShooter: Twin stick shooter starting point ) and got it working with the latest UE4 Version (was only some minor stuff to fix).

Sadly I am only learning Blueprints right now and the project is written in C++, where it also has Blueprints.

The thing is:

Moving the mouse lets the Owen Actor look around where the mouse is pointing. If I emulate a 2nd player (Dedicated Server Checkbox checked or not), then the mouse look is not being replicated. Can this only be done in C++, since it is a C++ project or can it also be done using Blueprints?

(Asking this, since I tried to use BP Replication and it somehow did not work, but I bet I just did something wrong)

Either yes or no: Can someone point me in the right direction? That would be nice.

Greetings,

Hi, I’m pretty sure your problem can be solved in Blueprints. It may have been an issue if a C++ parent class of your Blueprint would override certain settings after initiliazation, but the C++ classes in your linked project don’t do anything like this. Aside from Yaw, is movement replicated?

I think the issue may be that the Yaw that you see is only set client-side, in a way that the value not replicated. I’m not sure how Yaw is actually set, from the code you linked (haven’t downloaded the project). The best I can find is this in TwinStickShooterPlayer.cpp:

But I don’t see where the value of AimAtAngle is actually used in other cpp files, maybe its used in the level blueprint? You could try out this: In C++, ATwinStickShooterPlayerController::LookAtMouseCursor(), manually set the pawn’s actor rotation using SetActorRotation. If you can find where AimAtAngle is used in the level blueprints or pawn’s event graph, can you post a screenshot of the setup?

Thank you for the reply, NisshokuZK.

Aside from the “event tick” (how i would call it now) yaw, everything is replicated. The Character updates properly whenever movement with the keyboard keys is done, only the AimAtAngle with the mouse is not being updated.

I also added a Weapon via Blueprint and picking it up is being replicated as well.

I will check the C++ files and Project right away :slight_smile:

EDIT:

AimAtAngle is not defined in the Level Blueprint and TSS_Hero is the Character’s Blueprint, which is empty as well. Everything is completely C++ based.

AimAtAngle is defined in the following places:

TwinStickShooterCharacter.cpp:


ATwinStickShooterCharacter::ATwinStickShooterCharacter(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
...
AimAtAngle = 0;
}

TwinStickShooterCharacter.h:


class ATwinStickShooterCharacter : public ACharacter
{
...
	//Current Aiming Angle initial is 0;
	/** UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Aimer)  **/
	UPROPERTY(EditAnywhere, Category = Aimer)
	float AimAtAngle;
...
}

TwinStickShooterPlayerController.cpp:


void ATwinStickShooterPlayerController::LookAtMouseCursor()
{
	ATwinStickShooterCharacter* const MyPawn = (ATwinStickShooterCharacter*)GetPawn();
	if (MyPawn)
	{
...
		//The Aim at angle for the character
		MyPawn->AimAtAngle = ((acosf(FVector::DotProduct(PlayerDirection, MouseDirection))) * (180 / 3.1415926));
...
}

TwinStickShooterPlayerController.h:


UCLASS()
class ATwinStickShooterPlayerController : public APlayerController
{
	GENERATED_UCLASS_BODY()

	//Current Aiming Angle initial is 0;
	/** UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Aimer) **/
	UPROPERTY(EditAnywhere, Category = Aimer)
	float AimAtAngle;
...
}

I can’t find any other instances of AimAtAngle nor anywhere within the Project’s Blueprints.

EDIT:

Tried it with C++ and the SetActorRotation, but I’m not a C++ person (so far). Failed with implementing SetActorRotation on the C++ side. ^^’

This post by Tom Shannon has provided me some insight on what the problem is. Be sure to check it out.

Ignore AimAtAngle for now, it seems to be a variable that isn’t further used. Also, calling SetActorRotation in C++ isn’t going to help for synchronization unless it happens server-side. So what needs to be done is, you need to request the server to change your pawn’s rotation. Check out the post I linked and the third BP diagram in particular. Hope that helps. :slight_smile:

Thanks for the link, but it isn’t working. I added the BP nodes as how it is shown there, but nothing happens, except that now one player sees the other facing in the W Key Direction, instead of the Actor also turning and looking in the other directions :confused:

Still investigating it.

Here’s my current EventGraph from TSS_Hero as attachement.

EDIT:

Oh wait, do you mean the one I followed or the one above that one?

Hmm…I “google’d” a lot and found no solution for the problem, except others also having this problem, that extending the Top Down Example to have mouse look causes it to only work for a single player. It can work for more than one player, if both players are clients and connect to a dedicated server, but a peer 2 peer solution…haven’t found one so far.

Bump:

I’m highly lost with getting it replicated :confused: I tried several suggestions and examples I found to replicate it with Blueprints, but somehow it won’t work :frowning: