您的位置:首页 > 房产 > 家装 > 镇江专业网站建设制作_b2b服务商网站大全_广州seo代理计费_秦皇岛百度推广

镇江专业网站建设制作_b2b服务商网站大全_广州seo代理计费_秦皇岛百度推广

2025/3/13 4:13:05 来源:https://blog.csdn.net/qq_38785599/article/details/146055017  浏览:    关键词:镇江专业网站建设制作_b2b服务商网站大全_广州seo代理计费_秦皇岛百度推广
镇江专业网站建设制作_b2b服务商网站大全_广州seo代理计费_秦皇岛百度推广

78、The character class

要迁移文件夹时,右键选择migrate。可以跨项目migrate

创建一个c++类


80、character input

arrow component指示前方.设置网格和动画


81、character camera and springarm

蓝图中的这个选项,对应bUseControllerRotationPitch属性

use pawn control rotation可以在pawn不转动的情况下,只转动弹簧臂

但是这时候按w\s是沿着人物的前方、后方移动,而不是人物转向相机所在的方向移动。

注意 Controller和Capsule是不同物体,所以可能controller转动,但capsule不转动。

-----------SlashCharacter.h--------------
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "SlashCharacter.generated.h"class USpringArmComponent;
class UCameraComponent;UCLASS()
class MYPROJECT_API ASlashCharacter : public ACharacter
{GENERATED_BODY()public:// Sets default values for this character's propertiesASlashCharacter();// Called every framevirtual void Tick(float DeltaTime) override;// Called to bind functionality to inputvirtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;protected:// Called when the game starts or when spawnedvirtual void BeginPlay() override;void MoveForward(float Value);void MoveRight(float Value);void Turn(float Value);void LookUp(float Value);
private:UPROPERTY(VisibleAnywhere)USpringArmComponent* CameraBoom;UPROPERTY(VisibleAnywhere)UCameraComponent* ViewCamera;
};
------SlashCharacter.cpp------------------
#include "Characters/SlashCharacter.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
// Sets default values
ASlashCharacter::ASlashCharacter()
{// 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;bUseControllerRotationPitch = false;bUseControllerRotationYaw = false;bUseControllerRotationRoll = false;CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));CameraBoom->SetupAttachment(GetRootComponent());CameraBoom->TargetArmLength = 300.f;ViewCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("ViewCamera"));ViewCamera->SetupAttachment(CameraBoom);}// Called when the game starts or when spawned
void ASlashCharacter::BeginPlay()
{Super::BeginPlay();}// Called every frame
void ASlashCharacter::Tick(float DeltaTime)
{Super::Tick(DeltaTime);}// Called to bind functionality to input
void ASlashCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{Super::SetupPlayerInputComponent(PlayerInputComponent);PlayerInputComponent->BindAxis(FName("MoveForward"), this, &ASlashCharacter::MoveForward);PlayerInputComponent->BindAxis(FName("Turn"), this, &ASlashCharacter::Turn);PlayerInputComponent->BindAxis(FName("LookUp"), this, &ASlashCharacter::LookUp);PlayerInputComponent->BindAxis(FName("MoveRight"), this, &ASlashCharacter::MoveRight);
}void ASlashCharacter::MoveForward(float Value)
{if (Controller && (Value != 0.f)){FVector Forward = GetActorForwardVector();AddMovementInput(Forward, Value);}
}void ASlashCharacter::MoveRight(float Value)
{if (Controller && (Value != 0.f)){FVector Right = GetActorRightVector();AddMovementInput(Right, Value);}
}void ASlashCharacter::Turn(float Value)
{AddControllerYawInput(Value);
}void ASlashCharacter::LookUp(float Value)
{AddControllerPitchInput(Value);
}


83、control direction

实现角色朝向相机所看的角度移动 

-------SlashCharacter.cpp----------
void ASlashCharacter::MoveForward(float Value)
{if (Controller && (Value != 0.f)){//find out which way is forwardconst FRotator ControlRotation = GetControlRotation();const FRotator YawRotation(0.f, ControlRotation.Yaw, 0.f);const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);AddMovementInput(Direction, Value);}
}void ASlashCharacter::MoveRight(float Value)
{if (Controller && (Value != 0.f)){const FRotator ControlRotation = GetControlRotation();const FRotator YawRotation(0.f, ControlRotation.Yaw, 0.f);const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);AddMovementInput(Direction, Value);}
}

movement组件的orient能够让角色面朝移动方向

rotation rate能够改变角色转向移动的快慢

c++实现

----------SlashCharacter.cpp--------
ASlashCharacter::ASlashCharacter()
{// 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;bUseControllerRotationPitch = false;bUseControllerRotationYaw = false;bUseControllerRotationRoll = false;GetCharacterMovement()->bOrientRotationToMovement = true;GetCharacterMovement()->RotationRate = FRotator(0.f, 400.f, 0.f);CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));CameraBoom->SetupAttachment(GetRootComponent());CameraBoom->TargetArmLength = 300.f;ViewCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("ViewCamera"));ViewCamera->SetupAttachment(CameraBoom);}

 



84、hair and eyebrow

新增模块HairStrandsCore

----------MyProject.Build.cs-------
public class MyProject : ModuleRules
{public MyProject(ReadOnlyTargetRules Target) : base(Target){PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HairStrandsCore" });PrivateDependencyModuleNames.AddRange(new string[] {  });// Uncomment if you are using Slate UI// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });// Uncomment if you are using online features// PrivateDependencyModuleNames.Add("OnlineSubsystem");// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true}
}

重新构建项目,删掉三个自动生成的文件然后再生成

 

----------.h---------------
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "SlashCharacter.generated.h"class USpringArmComponent;
class UCameraComponent;
class UGroomComponent;UPROPERTY(VisibleAnywhere, Category = Hair)UGroomComponent* Hair;UPROPERTY(VisibleAnywhere, Category = Hair)UGroomComponent* Eyebrows;
----------------.cpp---------Hair = CreateDefaultSubobject<UGroomComponent>(TEXT("Hair"));Hair->SetupAttachment(GetMesh());Hair->AttachmentName = FString("head");Eyebrows = CreateDefaultSubobject<UGroomComponent>(TEXT("Eyebrows"));Eyebrows->SetupAttachment(GetMesh());Eyebrows->AttachmentName = FString("head");

 然后选择groom资产(我这里没有groom资产,所以没选

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com