I'm attempting to spawn objects, place some force on them, and then when they fall below x, destroy them.
I've pulled some code from the following tutorial: Components and Collisions to get me started.
UWorld *w = GetWorld();
APlayerCameraManager *cMgr = GetCameraManager();
UClass *uc = AProjectile::StaticClass();
FTransform t(cMgr->GetCameraRotation(), cMgr->GetCameraLocation());
always = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
AProjectile *p = w->SpawnActorDeferred<AProjectile>(uc,
p->ForwardForce = ForwardForce;
p->UpwardForce = UpwardForce;
#define SOBJ_ROOT TEXT("RootComponent")
#define SOBJ_MESH TEXT("Mesh")
#define PROFILE_NAME TEXT("PhysicsActor")
#define SPHR_DIR TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere")
PrimaryActorTick.bCanEverTick = true;
USphereComponent* sCmp = NULL;
sCmp = CreateDefaultSubobject<USphereComponent>(SOBJ_ROOT);
RootComponent = sCmp;
mesh = CreateDefaultSubobject<UStaticMeshComponent>(SOBJ_MESH);
static ConstructorHelpers::FObjectFinder<UStaticMesh> asset(SPHR_DIR);
mesh->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
FRotator cameraRotation = GetCameraRotation();
FVector up, forward, upAndForward;
up = RotationToDirection(cameraRotation, EAxis::Z) * UpwardForce;
forward = RotationToDirection(cameraRotation, EAxis::X) * ForwardForce;
upAndForward = up + forward;
void AProjectile::Tick(float DeltaTime)
FVector l = GetActorLocation();
if (l.Z < -50000.0f)
(FYI - The overuse of temp variables and the
#define stuff is for readability. The engine and API enjoy naming things so long they need punctuation, but this site wraps on 80 char columns.)
Visually, things are working as expected. However, when viewing properties of the items that are spawned, only the innermost "component" has it's Z adjusting. The "Root Component" (Assuming that is the correct term), and the one in between have a static position. Nothing spawned ever gets deleted.
When I add force to the mesh I created,
mesh->AddImpulse(upAndForward);, how do I make that force effect everything associated with that mesh?
Thanks in advance for any help!
Jan 17 '17 at 08:11 PM
in C++ Programming