Skip to content

Instantly share code, notes, and snippets.

@strobe
Last active February 15, 2016 20:55
Show Gist options
  • Save strobe/5a32e502563a214a846c to your computer and use it in GitHub Desktop.
Save strobe/5a32e502563a214a846c to your computer and use it in GitHub Desktop.
UE4 snippets
const FVector Impulse = FVector(0.f, 0.f, JumpImpulse);
Ball->AddImpulse(Impulse);
const FVector Torque = FVector(0.f, 0.f, 1.0f);
Ball->AddTorque(Torque);
// Structure to hold one-time initialization
struct FConstructorStatics
{
ConstructorHelpers::FObjectFinderOptional<UStaticMesh> BoxMesh;
FConstructorStatics()
: BoxMesh(TEXT("/Game/Meshes/Box.Box"))
{
}
};
static FConstructorStatics ConstructorStatics;
// Create mesh component for the box
BoxC = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("Box00"));
BoxC->SetStaticMesh(ConstructorStatics.BoxMesh.Get());
BoxC->BodyInstance.SetCollisionProfileName(UCollisionProfile::PhysicsActor_ProfileName);
BoxC->SetSimulatePhysics(true);
BoxC->SetAngularDamping(0.1f);
BoxC->SetLinearDamping(0.1f);
BoxC->BodyInstance.MassScale = 2.f;
BoxC->SetNotifyRigidBodyCollision(true);
RootComponent = BoxC;
/** Thruster force*/
Thruster = PCIP.CreateDefaultSubobject<UPhysicsThrusterComponent>(this, TEXT("Thruster00"));
Thruster->ThrustStrength = GravityPower;
Thruster->bAutoActivate = 1;
Thruster->AttachParent = BoxC;
/** Pawn Header */
// APawn interface
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) OVERRIDE;
/** Cpp */
void ACppRollingBall::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
InputComponent->BindAxis("MoveRight", this, &ACppRollingBall::MoveRight);
InputComponent->BindAction("Jump", IE_Pressed, this, &ACppRollingBall::Jump);
}
/** Header */
//General Log
DECLARE_LOG_CATEGORY_EXTERN(CppPlanetoid, Log, All);
/** Cpp file */
//General Log
DEFINE_LOG_CATEGORY(CppPlanetoid);
/** Header */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Planet)
AActor* Planet
ACppRollingGameMode::ACppRollingGameMode(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
// set default pawn class to our ball
DefaultPawnClass = ACppRollingBall::StaticClass();
}
DrawDebugLine(
GetWorld(),
start,
target,
FColor(255,0,0),
false, 0.1f, 0,
2.f
);
/** Header */
virtual void Tick(float dt) OVERRIDE;
/** In Constructor */
// enable the tick updates
PrimaryActorTick.bCanEverTick = true;
SetActorTickEnabled(true);
RegisterAllActorTickFunctions(true, true);
/** Implementation */
void APlanetActor::Tick( float DeltaSeconds )
{
Super::Tick(DeltaSeconds);
}
/** Simple */
UENUM()
enum EMyEnum
{
Name, /**&lt; Comment */
};
/** For Blueprints */
UENUM()
namespace EMyEnum
{
enum Type
{
Name UMETA(DisplayName = "DisplayName"), /**&lt; Comment */
};
}
/** Header */
virtual void BeginPlay() OVERRIDE;
/** Implementation */
void APlanetActor::BeginPlay()
{
if (Auto == true) {
for (TActorIterator<AActor> ActorItr(GetWorld()); ActorItr; ++ActorItr) {
if (ActorItr->GetName() == "Planetoid")
Planet = Cast<AActor>(*ActorItr);
}
}
}
FVector target = Planet->GetActorLocation();
FVector start = Thruster->GetComponentLocation();
FVector direction = -(target - start);
FRotator targetRot = FRotationMatrix::MakeFromX(direction).Rotator();
// set result to actor component
Thruster->SetWorldRotation(targetRot, true);
UINTERFACE()
class UFoo : public UInterface
{
GENERATED_UINTERFACE_BODY()
};
class IFoo
{
GENERATED_IINTERFACE_BODY()
};
UE_LOG(CppPlanetoid, Warning, TEXT("target rot p %f r %f y %f"), targetRot.Pitch, targetRot.Roll, targetRot.Yaw);
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Magenta, TEXT("planeta actor tick"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment