-
在UE4中创建角色,首先需要有相应的角色模型,这里有一个免费的网站可以找到相应角色,是Adobe公司下面的一个网站 https://www.mixamo.com/,网站中有很多的免费的角色和动画
选中一个自己喜欢的角色和动画,下载下来。 -
把下载下来的角色和动画可以导入到UEEditor中。在Content下面新建一个文件夹Character,右键鼠标可以导入
-
新建Charactor类MainCharactor(继承自ACharacter ),在类中添加摇臂和摄像机
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "MainCharacter.generated.h"
UCLASS()
class FIRSTPROJECT_API AMainCharacter : public ACharacter {
GENERATED_BODY()
public:
// Sets default values for this character's properties
AMainCharacter();
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class USpringArmComponent* cameraSpringArm;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class UCameraComponent* followCamera;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "MainCharacter.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
// Sets default values
AMainCharacter::AMainCharacter() {
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
cameraSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArm"));
cameraSpringArm->SetupAttachment(GetRootComponent());
cameraSpringArm->TargetArmLength = 400.0;
cameraSpringArm->bUsePawnControlRotation = true; //摇臂跟着控制器的旋转
followCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
followCamera->SetupAttachment(cameraSpringArm, USpringArmComponent::SocketName);
followCamera->bUsePawnControlRotation = false; //摄像机不跟着摇臂旋转
}
// Called when the game starts or when spawned
void AMainCharacter::BeginPlay() {
Super::BeginPlay();
}
// Called every frame
void AMainCharacter::Tick(float DeltaTime) {
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AMainCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
- 新建角色对应的蓝图类
把下载动画和骨骼网格体导图进去就可以了
一个简单的角色就创建出来了。