虚幻引擎基础
获得角色控制权的两种方式
一、 1、在内容浏览器第三人称模板中的小白人拖入到地图中。 2、选中小白人在细节面板中搜索详情中搜索possess。 3、将自动控制玩家设为玩家0。 二、 1、在世界场景设置中找到gamemode将游戏模式覆盖选为thirdpersongamemmode。 2、在模式基础中找到玩家出生点拖入地图。
材质
1、地形材质混合类型
权重混合,同一图层上进行贴图绘制,适用于水
透明度混合,不同图层上进行贴图绘制,与预览权重有关,适用于地表
日夜更替效果实现
1、将定向光源改为可移动,取消勾选投射静态阴影 2、打开关卡蓝图
Update Sun Direction 根据太阳位置改变天空颜色
Sun speed (float类型的变量)决定太阳的旋转速度
虚幻引擎C++编程入门
打印字符串
蓝图实现 1、创建蓝图类 2、将蓝图类拖入到场景中 二、c++实现
#include "Kismet/KismetSystemLibrary.h"
void APrint_hello::BeginPlay()
{
Super::BeginPlay();
UKismetSystemLibrary::PrintString(this, TEXT("hello ue"));
}
FloatingActor
官方文档 代码实现
#include "FloatingActor.h"
AFloatingActor::AFloatingActor()
{
PrimaryActorTick.bCanEverTick = true;
VisualMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
VisualMesh->SetupAttachment(RootComponent);
static ConstructorHelpers::FObjectFinder<UStaticMesh> CubeVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Cube.Shape_Cube"));
if (CubeVisualAsset.Succeeded())
{
VisualMesh->SetStaticMesh(CubeVisualAsset.Object);
VisualMesh->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
}
}
void AFloatingActor::BeginPlay()
{
Super::BeginPlay();
}
void AFloatingActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FVector NewLocation = GetActorLocation();
FRotator NewRotation = GetActorRotation();
float RunningTime = GetGameTimeSinceCreation();
float DeltaHeight = (FMath::Sin(RunningTime + DeltaTime) - FMath::Sin(RunningTime));
NewLocation.Z += DeltaHeight * 20.0f;
float DeltaRotation = DeltaTime * 20.0f;
NewRotation.Yaw += DeltaRotation;
SetActorLocationAndRotation(NewLocation, NewRotation);
}
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "FloatingActor.generated.h"
UCLASS()
class FLOATOBJECT_API AFloatingActor : public AActor
{
GENERATED_BODY()
public:
AFloatingActor();
UPROPERTY(VisibleAnywhere)
UStaticMeshComponent* VisualMesh;
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
};
游戏控制多个摄像机的切换
一、两个摄像机的切换 官方文档 二、多个摄像机的切换 代码实现
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "CameraDirector.generated.h"
UCLASS()
class FLOATOBJECT_API ACameraDirector : public AActor
{
GENERATED_BODY()
public:
ACameraDirector();
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
float TimeToNextCameraChange;
UPROPERTY(EditAnywhere)
AActor* Cameras[6];
};
#include "CameraDirector.h"
#include "Kismet/GameplayStatics.h"
int i = 0;
ACameraDirector::ACameraDirector()
{
PrimaryActorTick.bCanEverTick = true;
}
void ACameraDirector::BeginPlay()
{
Super::BeginPlay();
}
void ACameraDirector::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
const float TimeBetweenCameraChanges = 2.0f;
const float SmoothBlendTime = 0.75f;
TimeToNextCameraChange -= DeltaTime;
if (TimeToNextCameraChange <= 0.0f)
{
TimeToNextCameraChange += TimeBetweenCameraChanges;
APlayerController* OurPlayerController = UGameplayStatics::GetPlayerController(this, 0);
if (OurPlayerController)
{
while ((OurPlayerController->GetViewTarget() != Cameras[i])&& (Cameras[i] != nullptr)&&i<6)
{
OurPlayerController->SetViewTargetWithBlend(Cameras[i], SmoothBlendTime);
i++;
break;
}
}
}
if (i == 6)
i = 0;
}
|