Im making an RPC function that can hold actions. Such as dodge, sprint, attack, etc. I’ve made an enum that is a bitmask to conserve memory and ive made a new player controller so everyone could have it and so that my actor file isnt so clogged. Everything would be in the playercontroller file. So i did all this and so far im starting off with what should be the easiest… “sprint” i created the start sprint in my character function and i made a pointer to my player controller -which im starting to think i should just put the startsprint input in the player controller too, but we’ll see to whoever responds to this- and im either getting nothing my character stays walking or i get that my characrter tries to start running but the sever isnt allowing the character to change run speeds so its locking it at walk and all i see is the client attempting to run but not on the server. (ill link code and what not). Anyway, ive been trying to get used to bitmasks and bitflags and i thought i had it, maybe im doing something wrong. I thought i had everything right, but clearly sometihing is up! lol. I think it has something to do with the pointers or maybe the flags arent turning on correctly but we will see. Any help is appreciated!
ill have a video when it uploads. As of now, here is the code… the important parts.
UPDATE : video link
PlayerControllerCustom.h
#define TEST_BIT(Bitmask, Bit) (Bitmask & static_cast<uint32>(Bit))
#define SET_BIT(Bitmask, Bit) (Bitmask |= static_cast<uint32>(Bit))
#define CLEAR_BIT(Bitmask, Bit) (Bitmask &= ~( static_cast<uint32>(Bit)))
UENUM(BlueprintType, meta = (Bitflags, UseEnumValuesAsMaskValuesInEditor = "true"))
enum class EMovementCallFlags : uint8
{
Dodging = 1,
Sprinting = 2,
Attacking = 4,
Blocking = 8,
};
ENUM_CLASS_FLAGS(EMovementCallFlags)
PlayerControllerCustom.cpp
bool APlayerControllerCustom::DoAction_Validate()
{
if (Attributes.RunSpeed < Attributes.MaxPlayerSpeed())
{
return true;
}
else return false;
}
void APlayerControllerCustom::DoAction_Implementation()
{
MultiCastAction();
}
void APlayerControllerCustom::MultiCastAction_Implementation()
{
Sprint();
}
void APlayerControllerCustom::Sprint()
{
if(TEST_BIT(MovementCallFlags, EMovementCallFlags::Sprinting))
{
TObjectIterator<APlayerCharacter>PlayerCharacter;
if(!PlayerCharacter) return;
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = Attributes.RunSpeed;
PlayerCharacter->UpdateStamina();
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow,
TEXT("SPRINTINGGGGGG"));
}
else {
TObjectIterator<APlayerCharacter>PlayerCharacter;
if(!PlayerCharacter) return;
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = Attributes.WalkSpeed;
PlayerCharacter->UpdateStamina();
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("WALKING"));
}
}
PlayerCharacter.CPP
void APlayerCharacter::StartSprint()
{
if (Role < ROLE_Authority)
{
if (ControllerRef != nullptr){
SET_BIT(ControllerRef->MovementCallFlags, EMovementCallFlags::Sprinting);
ControllerRef->DoAction();
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("SPRINT TRUE"));
if(TEST_BIT(ControllerRef->MovementCallFlags, EMovementCallFlags::Sprinting))
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("FLAG IS TRUE"));
}
}
}
}
void APlayerCharacter::StopSprint()
{
if (Role < ROLE_Authority)
{
if (ControllerRef != nullptr ){
CLEAR_BIT(ControllerRef->MovementCallFlags, EMovementCallFlags::Sprinting);
ControllerRef->DoAction();
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("SPRINT FALSE"));
}
}
}