2018-02-01 10:41:10 sky1466181491 阅读数 4003

1)Pawn是马甲,Controller是驱动马甲的大脑。 Controller和Pawn相对独立,不一定谁必须有谁。一个Controller至多能控制一个Pawn,一个Pawn至多能被一个Controller控制。

2)Character是Pawn的一种。 

至于Player,没有这个类,只是在Blueprint里有带有player字眼的节点,比如Get Player Character节点和Get Player Pawn节点。

Representing Players, Friends, and Foes in the World

pawn_lander.png

Pawn

Pawn 是一个演员,可以是世界上的“代理人”。一个控制器(Controller)可以拥有一个Pawn,他们被设置为容易接受输入,他们

可以各种各样的其他类似玩家的东西。请注意,一个Pawn不被认为是人形。

Character

Character 是一个人形的 Pawn.它带有一个用于碰撞的CapsuleComponent和一个CharacterMovementComponent。它可以做

基本的类人动作,它可以在整个网络上流畅地复制动作,并且具有一些动画相关的功能。

Controlling Pawns With Player Input or AI Logic

controller_lander.png

Controller

Controller 是一个负责指挥Pawn的Actor。 他们通常有两种,AIController和PlayerController。一个Controller可以“拥有”

一个Pawn来控制它。

PlayerController

PlayerController 是Pawn和人类玩家控制它之间的接口。PlayerController实质上代表了人类玩家的意愿。

AIController

一个AIController就是它的声音。一个模拟的“意志”,可以控制一个Pawn。

Displaying Information to Players

camera_lander.png

HUD

HUD 是“抬头显示器”,或在2D屏幕上显示的是常见于许多游戏。考虑健康,弹药,枪瞄准器等。每个PlayerController通常具有其中

之一。

Camera

PlayerCameraManager是一个球员的“眼球”,并管理他的行为。每个PlayerController通常也有其一

Setting and Tracking the Rules of the Game

hud_lander.png

GameMode

 “游戏”的概念分为两​​类。游戏模式和游戏状态Game Mode and Game State  是游戏的定义,包括像游戏规则的事情,

赢得条件。它只存在于服务器上。它通常不应该有太多的数据在播放过程中发生变化,绝对不应该有客户需要知道的瞬态数据。

GameState

游戏状态( GameState ) 包括游戏,这可能包括像关连球员名单,得分,那里的作品是一盘棋,或者你在一个开放的世界游戏

完成的任务是什么列表的状态。GameState存在于服务器和所有客户端上,并且可以自由复制以保持所有的机器都是最新的。

PlayerState

PlayerState是在游戏中,参与者的状态,诸如人类演奏者或者是模拟播放机的机器人。存在作为游戏一部分的非玩家AI不会有

PlayerState。在PlayerState中适当的示例数据包括玩家姓名,得分,类似于MOBA之类的比赛级别,或者玩家是否正在CTF

游戏中携带该旗子。所有玩家的PlayerStates都存在于所有机器上(不像PlayerControllers),并且可以自由复制以保持同步。

框架类关系

这个流程图说明了这些核心游戏类如何相互关联。游戏由GameMode和GameState组成。加入游戏的人类玩家与玩家控制器相关联。这些PlayerControllers允许玩家在游戏中拥有棋子,因此他们可以在关卡中拥有物理表征。PlayerControllers还为玩家提供输入控件,平视显示器或HUD,以及用于处理摄像机视图的PlayerCameraManager。

GameFramework.png

2017-11-22 14:24:30 WAN_EXE 阅读数 741

Pawn这个单词不会翻译,找不到可以形象描述这个单词的汉语,大概的意思就是可以通过很多的Components合成一个含有多种属性状态的物体。

这里主要是如果获取键盘和鼠标的输入,

在Edit  -- Project Setting -- Engine -- Input里面控制,有两种属性,一种是Action Mappings,另外一种是Axis Mapping.

这两种是有区别的,Action主要针对不是连续的,比如跳,射击等,Axis是连续的,比如移动,旋转等。

贴上代码

MyPawn.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "MyPawn.generated.h"

UCLASS()
class UNREALLEARN_API AMyPawn : public APawn
{
	GENERATED_BODY()

public:
	// Sets default values for this pawn's properties
	AMyPawn();

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;
	
	UPROPERTY(EditAnywhere)
	USceneComponent* OurVisibleComponent;

	//Input functions
	void Move_XAxis(float AxisValue);
	void Move_YAxis(float AxisValue);
	void StartGrowing();
	void StopGrowing();

	//Input variables
	FVector CurrentVelocity;
	bool bGrowing;
};

MyPawn.cpp

// Fill out your copyright notice in the Description page of Project Settings.


#include "MyPawn.h"
#include "Camera/CameraComponent.h"

// 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 we can 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 our root component. Offset and rotate the camera.
	OurCamera->SetupAttachment(RootComponent);
	OurCamera->SetRelativeLocation(FVector(-250.0f, 0.0f, 250.0f));
	OurCamera->SetRelativeRotation(FRotator(-45.0f, 0.0f, 0.0f));
	OurVisibleComponent->SetupAttachment(RootComponent);

}

// Called when the game starts or when spawned
void AMyPawn::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AMyPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	// Handle growing and shrinking based on our "Grow" action
    {
        float CurrentScale = OurVisibleComponent->GetComponentScale().X;
        if (bGrowing)
        {
            // Grow to double size over the course of one second
            CurrentScale += DeltaTime;
        }
        else
        {
            // Shrink half as fast as we grow
            CurrentScale -= (DeltaTime * 0.5f);
        }
        // Make sure we never drop below our starting size, or increase past double size.
        CurrentScale = FMath::Clamp(CurrentScale, 1.0f, 2.0f);
        OurVisibleComponent->SetWorldScale3D(FVector(CurrentScale));
    }

    // Handle movement based on our "MoveX" and "MoveY" axes
    {
        if (!CurrentVelocity.IsZero())
        {
            FVector NewLocation = GetActorLocation() + (CurrentVelocity * DeltaTime);
            SetActorLocation(NewLocation);
        }
    }
}

// Called to bind functionality to input
void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	// Respond when our "Grow" key is pressed or released.
    InputComponent->BindAction("Grow", IE_Pressed, this, &AMyPawn::StartGrowing);
    InputComponent->BindAction("Grow", IE_Released, this, &AMyPawn::StopGrowing);

    // Respond every frame to the values of our two movement axes, "MoveX" and "MoveY".
    InputComponent->BindAxis("MoveX", this, &AMyPawn::Move_XAxis);
    InputComponent->BindAxis("MoveY", this, &AMyPawn::Move_YAxis);
}

void AMyPawn::Move_XAxis(float AxisValue)
{
    // Move at 100 units per second forward or backward
    CurrentVelocity.X = FMath::Clamp(AxisValue, -1.0f, 1.0f) * 100.0f;
}

void AMyPawn::Move_YAxis(float AxisValue)
{
    // Move at 100 units per second right or left
    CurrentVelocity.Y = FMath::Clamp(AxisValue, -1.0f, 1.0f) * 100.0f;
}

void AMyPawn::StartGrowing()
{
    bGrowing = true;
}

void AMyPawn::StopGrowing()
{
    bGrowing = false;
}


2017-06-23 13:16:36 maya_00 阅读数 274
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "MyPawn.generated.h"

UCLASS()
class ZWEIPROJEKT_API AMyPawn : public APawn
{
    GENERATED_BODY()

private:
    float XScaleIncrement = 0.0;
    float YScaleIncrement = 0.0;
    float Distance = 0.0;
    float ZPosition = 0.0;
    bool RightButtonPressed = false;
    bool MiddleBtnPressed = false;

public:
    // Sets default values for this pawn's properties
    AMyPawn();

    UPROPERTY(VisibleAnywhere)
    USpringArmComponent* CameraArm;

    UPROPERTY(VisibleAnywhere)
    UCameraComponent* Camera;

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;
    void XAxis(float Scale);
    void YAxis(float Scale);
    void MiddleButtonAxis(float MiddleButtonAxis);
    void RightMouseButtonPressed();
    void RightMouseButtonReleased();
    void MiddleButtonPressed();
    void MiddleButtonReleased();

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 "MyPawn.h"
#include "Kismet/KismetMathLibrary.h"


// 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;

    CameraArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraArm"));
    RootComponent = CameraArm;

    Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
    Camera->SetupAttachment(CameraArm);

    CameraArm->bDoCollisionTest = 0;

    FVector WorldOriginalCenter = FVector::ZeroVector;
    SetActorLocation(WorldOriginalCenter);
    Distance = CameraArm->TargetArmLength;
    CameraArm->CameraRotationLagSpeed = 10.0;
    CameraArm->bEnableCameraRotationLag = 1;
}

// Called when the game starts or when spawned
void AMyPawn::BeginPlay()
{
    Super::BeginPlay();
    
}

// Called every frame
void AMyPawn::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
    Super::SetupPlayerInputComponent(PlayerInputComponent);
    PlayerInputComponent->BindAxis("XAxis",this,&AMyPawn::XAxis);
    PlayerInputComponent->BindAxis("YAxis", this, &AMyPawn::YAxis);
    PlayerInputComponent->BindAxis("MiddleButtonAxis", this, &AMyPawn::MiddleButtonAxis);

    PlayerInputComponent->BindAction("RightMouseButton", IE_Pressed,this, &AMyPawn::RightMouseButtonPressed);
    PlayerInputComponent->BindAction("RightMouseButton", IE_Released, this, &AMyPawn::RightMouseButtonReleased);
    PlayerInputComponent->BindAction("MiddleButtonPressed", IE_Pressed, this, &AMyPawn::MiddleButtonPressed);
    PlayerInputComponent->BindAction("MiddleButtonPressed", IE_Released, this, &AMyPawn::MiddleButtonReleased);

}

void AMyPawn::XAxis(float Scale) {
    if (RightButtonPressed)
    {
        FRotator CameraRotation = GetActorRotation();
        XScaleIncrement += Scale;
        FRotator ChangeRotation(CameraRotation.Pitch, XScaleIncrement, CameraRotation.Roll);
        SetActorRotation(ChangeRotation);
    }
}

void AMyPawn::YAxis(float Scale) {
    if (RightButtonPressed)
    {
        FRotator CameraRotation = GetActorRotation();
        YScaleIncrement -= Scale;
        YScaleIncrement = UKismetMathLibrary::Clamp(YScaleIncrement ,-80,80);
        FRotator ChangeRotation(YScaleIncrement, CameraRotation.Yaw, CameraRotation.Roll);
        SetActorRotation(ChangeRotation);
    }

    if (MiddleBtnPressed)
    {
        FVector CameraLocation = GetActorLocation();
        ZPosition = CameraLocation.Z;
        ZPosition += Scale;
        FVector ChangeLocation = FVector::ZeroVector;
        ChangeLocation.Z = ZPosition;
        SetActorLocation(ChangeLocation);
    }
}

void AMyPawn::MiddleButtonAxis(float Scale) {
    Distance += Scale;
    CameraArm->TargetArmLength = Distance;
}

void AMyPawn::RightMouseButtonPressed() {
    RightButtonPressed = true;
}

void AMyPawn::RightMouseButtonReleased() {
    RightButtonPressed = false;
}

void AMyPawn::MiddleButtonPressed() {
    MiddleBtnPressed = true;
}

void AMyPawn::MiddleButtonReleased() {
    MiddleBtnPressed = false;
}




unreal

阅读数 240

Unreal里的输入

阅读数 1186

没有更多推荐了,返回首页