TangibleCharacter can now be interactively controlled

This commit is contained in:
2024-02-02 15:48:27 -05:00
parent 4b3315eb76
commit d11fbca815
18 changed files with 96 additions and 28 deletions

View File

@@ -3,6 +3,7 @@
#include "Tangible.h"
#include "TangibleManager.h"
#include "IntegrationGameModeBase.h"
#define DEFAULT_BLUEPRINT (TEXT("TangibleStaticMesh"))
@@ -59,23 +60,37 @@ void UlxTangible::SetActorBlueprint(const FString &name) {
// Now create a new actor, unless the BP is nullptr.
if (blueprint != nullptr) {
// Create the actor.
FActorSpawnParameters params;
FVector location(0, 0, 0);
FRotator rotation(0, 0, 0);
UWorld* w = Manager->GetWorld();
FActorSpawnParameters params;
// Currently, the actor is spawned at (0,0,0), which is not good.
// We should spawn at the actor's current location. I'll get to it
// eventually.
FTransform transform;
transform.SetLocation(FVector(0,0,0));
transform.SetRotation(FQuat(FRotator(0,0,0)));
// Create the actor at the specified location even if there's something in the way.
params.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
AActor* a = w->SpawnActor(blueprint, &location, &rotation, params);
// Normally, SpawnActor runs the BeginPlay entry point. We
// want to delay that until after we've had a chance to set
// up the TangibleComponent.
params.bDeferConstruction = true;
AActor* a = w->SpawnActor(blueprint, &transform, params);
check(a != nullptr);
// Insert a TangibleComponent into the actor.
// Link the actor to its tangible, and the tangible to its actor.
UActorComponent* ac = a->AddComponentByClass(UlxTangibleComponent::StaticClass(), false, FTransform::Identity, false);
UlxTangibleComponent* tc = Cast<UlxTangibleComponent>(ac);
check(tc != nullptr);
// Make the tangible point to the actor and vice versa.
tc->Tangible = this;
CurrentActor = a;
// This executes the BeginPlay entry point. We have to do this here
// because we deferred it in SpawnActor.
a->FinishSpawning(transform, true);
}
}
@@ -140,3 +155,8 @@ void UlxTangible::SetTangiblePlane(AActor* target, const FString& plane) {
GetActorTangible(target)->Plane = FName(plane);
}
bool UlxTangible::IsCurrentPlayer(AActor* target) {
UlxTangible *tan = GetActorTangible(target);
AIntegrationGameModeBase *gamemode = tan->Manager->GetGameMode();
return (tan->TangibleId == gamemode->PlayerId);
}