// Sets default values AMyPawn::AMyPawn() { // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; //Set this pawn to be controlled by the lowest numbered player AutoPossessPlayer = EAutoReceiveInput::Player0; //Create a dummy root component to attach things to. RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent")); //create a camera and a visible object UCameraComponent* OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("OurCamera")); OurVisibleComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("OurVisibleComponent")); //attach our camera and visible object to the root OurCamera->AttachTo(RootComponent); (*OurVisibleComponent).AttachTo(RootComponent); //offset camera OurCamera->SetRelativeLocation(FVector(-250, 0, 250)); //rotate camera OurCamera->SetRelativeRotation(FRotator(-45, 0, 0)); InitLocation = GetActorLocation(); }
// Sets default values ASkateboardPawn::ASkateboardPawn() { // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; // Makes the first player take control of this pawn automatically AutoPossessPlayer = EAutoReceiveInput::Player0; // Create a dummy root component we can attach things to RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent")); // Create a camera and a visible object UCameraComponent* Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent")); Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComponent")); static ConstructorHelpers::FObjectFinder<UStaticMesh>CubeVisualAsset(TEXT("/Game/skateboard")); if (CubeVisualAsset.Succeeded()) { Mesh->SetStaticMesh(CubeVisualAsset.Object); Mesh->SetSimulatePhysics(true); //Mesh->SetMassOverrideInKg("", 100); } // Attach our camera and visible object to our root component. Offset and rotate the camera. Camera->AttachTo(Mesh); Camera->SetRelativeLocation(FVector(-450.0f, 0.0f, 450.0f)); Camera->SetRelativeRotation(FRotator(-45.0f, 0.0f, 0.0f)); Camera->SetWorldScale3D(FVector(1, 1, 1)); Mesh->AttachTo(RootComponent); }
// Sets default values AMyObjPawn::AMyObjPawn() { // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; // Set this pawn to be controlled by the lowest-numbered player (このポーンが最小値のプレイヤーで制御されるように設定) AutoPossessPlayer = EAutoReceiveInput::Player0; // ダミーキャラクターを置く RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent")); // Create a dummy root component we can attach things to.(親子付け可能なダミーのルートコンポーネントを作成) UCameraComponent* OurCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("OurCamera")); // Attach our camera and visible object to our root component. (カメラと可視オブジェクトをルートコンポーネントに親子付け。カメラをオフセットして回転) OurCamera->AttachTo(RootComponent); OurCamera->SetRelativeLocation(FVector(-350.0f, 0.0f, 100.0f)); OurCamera->SetRelativeRotation(FRotator(0.0f, 0.0f, 0.0f)); /** * Create/replace a section for this procedural mesh component. * @param SectionIndex Index of the section to create or replace. * @param Vertices Vertex buffer of all vertex positions to use for this mesh section. * @param Triangles Index buffer indicating which vertices make up each triangle. Length must be a multiple of 3. * @param Normals Optional array of normal vectors for each vertex. If supplied, must be same length as Vertices array. * @param UV0 Optional array of texture co-ordinates for each vertex. If supplied, must be same length as Vertices array. * @param VertexColors Optional array of colors for each vertex. If supplied, must be same length as Vertices array. * @param Tangents Optional array of tangent vector for each vertex. If supplied, must be same length as Vertices array. * @param bCreateCollision Indicates whether collision should be created for this section. This adds significant cost. */ // 動的オブジェクトを置く mProceduralMeshComponent = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("GeneratedMesh")); TArray<FVector> positions; TArray<FVector> normals; TArray<FVector2D> uvs; TArray<FColor> colors; TArray<FProcMeshTangent> tangents; TArray<int32> indices; ObjectParser(positions, normals, uvs, indices); for (size_t i = 0; i < positions.Num(); i++) { colors.Add(FColor(255, 255, 255, 255)); tangents.Add(FProcMeshTangent(1, 1, 1)); } ConstructorHelpers::FObjectFinder<UMaterial>* pMaterialAsset = new ConstructorHelpers::FObjectFinder<UMaterial>( _T("/Game/InfinityBladeAdversaries/Enemy/Enemy_Bear/Materials/M_Bear_Master.M_Bear_Master") ); if (pMaterialAsset->Succeeded()) { mMaterial = pMaterialAsset->Object; UE_LOG(LogTemp, Warning, TEXT("output : %s"), L"マテリアルロードに成功しました"); } else { UE_LOG(LogTemp, Warning, TEXT("output : %s"), L"マテリアルロードに失敗しました"); } mProceduralMeshComponent->CreateMeshSection(0, positions, indices, normals, uvs, colors, tangents, false); mProceduralMeshComponent->SetMaterial(0, mMaterial); mProceduralMeshComponent->AttachTo(RootComponent); }