Last active
February 15, 2016 20:55
-
-
Save strobe/5a32e502563a214a846c to your computer and use it in GitHub Desktop.
UE4 snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const FVector Impulse = FVector(0.f, 0.f, JumpImpulse); | |
Ball->AddImpulse(Impulse); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const FVector Torque = FVector(0.f, 0.f, 1.0f); | |
Ball->AddTorque(Torque); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Header */ | |
//General Log | |
DECLARE_LOG_CATEGORY_EXTERN(CppPlanetoid, Log, All); | |
/** Cpp file */ | |
//General Log | |
DEFINE_LOG_CATEGORY(CppPlanetoid); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Header */ | |
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Planet) | |
AActor* Planet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ACppRollingGameMode::ACppRollingGameMode(const class FPostConstructInitializeProperties& PCIP) | |
: Super(PCIP) | |
{ | |
// set default pawn class to our ball | |
DefaultPawnClass = ACppRollingBall::StaticClass(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DrawDebugLine( | |
GetWorld(), | |
start, | |
target, | |
FColor(255,0,0), | |
false, 0.1f, 0, | |
2.f | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Simple */ | |
UENUM() | |
enum EMyEnum | |
{ | |
Name, /**< Comment */ | |
}; | |
/** For Blueprints */ | |
UENUM() | |
namespace EMyEnum | |
{ | |
enum Type | |
{ | |
Name UMETA(DisplayName = "DisplayName"), /**< Comment */ | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UINTERFACE() | |
class UFoo : public UInterface | |
{ | |
GENERATED_UINTERFACE_BODY() | |
}; | |
class IFoo | |
{ | |
GENERATED_IINTERFACE_BODY() | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UE_LOG(CppPlanetoid, Warning, TEXT("target rot p %f r %f y %f"), targetRot.Pitch, targetRot.Roll, targetRot.Yaw); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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