Unreal engine 4 beginning (escape the room)

 the Unreal's class system :

Character is a Pawn ,Pawn is an Actor

Using UE_LOG to print to the output console

UE_LOG has different kind of color the present the message which are Warning Error Log and the format paramter just like the one in the printf function .it can print the string to the screen .

UPROPERTY marco would expose the property of class to the editor,VisibleAnywhere can not modify in the editor and EditAnywhere can be modified in the editor.

In this case . what we are gonna use the API is about line trace and physics handle  and grab component within the physics handle . input action binding and create the blueprint via C++ or the game object in the editor even though which is running or not .

let's glance a little bit of Physics handle Component.The documentation has not mention this ,so let me see in the someone blog.

PhysicsHandleComponent is used to grab and move the object with physics ,meanwhile it will make the object you grabbed to use the physics effect contineusily.So in this case we gonna use the it method GrabComponent,and it prototype is following :

GrabComponent

(
    UPrimitiveComponent * Component,//Components of actors whose rays intersect with each other
    FName InBoneName,//BoneName in here we are assagin as NAME_None ,because what we are gonna grab the object is not a humanroid or animal like dog
    FVector GrabLocation,//as it means that is location of grabbing
    bool bConstrainRotation//Are you wanna rotate the object which you grab 
)

The next we are going to talk about is ray which has a vector from the end point to the start point ,and its length .in the game world ,every physics colliders are simulate as the simple polygons .And the reason why we always do it is this is the method to improve our hardware performances .simple colliders has few triangles so it always run faster than using the complex colliders.

for instance,if we want to define the ray which we are going to detect which object it will intersect,so we need the start point and also the end point .we can use the view point which is real time movement point of our controlling actor in the UE4.

GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(

OUT FVector& pos,

OUT FRotator& rotation

)

And now we got the start point of the ray cast vector ,so how about the end point ,the end point is essientially the position we got from the GetPlayerVewPoint function plus the the direction that we are looking at ,how to obtain this direction ? ,we can use the member method Vector() which is represented as the forward direction we are looking at . UWorld::LineTraceSingleByObjectType function can help us to figure out which object we gonna grab .and its prototype is following:

bool LineTraceSingleByObjectType
(
    struct FHitResult & OutHit,//the information of hit 
    const FVector & Start,//the line start point
    const FVector & End,//the line end point
    const FCollisionObjectQueryParams & ObjectQueryParams,//which type of the object we gonna detect is available 
    const FCollisionQueryParams & Params//who is own this ray .
)

the following is the pseudocode :

//set up the query parameters
    FCollisionQueryParams cqp(FName(TEXT("")), false, GetOwner());

GetWorld()->LineTraceSingleByObjectType(
        OUT result,
        pos,
        LineTraceEnd,
        FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody), cqp);

the fourth parameter is that what we gonna detect object is the physics body, so now everything go well .let's go ahead.

In game we also use the keyboard press the specific key to move the obejct or do something else .so in UE4 we should talk about Action binding .the action can be specified as the specified key on the keyboard .And we will bind the action in the beginning of the game play.so in here is BeginPlay function in every component class.but we just bind them once in a class you want .and the bindAction function is in the UInputComponent so we should use the pointer which point to this component to access this method .And the prototype is following:

BindAction

(
    const FName ActionName,//the action name we put in the editor input tab.
    const EInputEvent KeyEvent,//Pressed Released or hold the key 
    UserClass* Object,//who own this input 
    typename DelegateType::template TUO...,// is a void type callback function if the action is triggered it will run
    VarTypes... Vars//this parameter can ignore in this case 
)

 

triggerVolume : if the object contains collider on which it will trigger ,

we can get the overlapping actors on this trigger volume with GetOverlappingActors(OUT TArray<AActor*>array);

we iterate through every actor object by for(const auto& item:array).

the next we gonna talk about is blueprint which the powerful tool to associated with c++ ,so sometimes Blueprint is the better choice.For example we defining our door swing as a curve.we can create an event called OnOpenRequsted.Using UPROPERTY(BlueprintAssignable) *to expose the property of c++ class .

if you to expose the delegate function to blueprint.you should set the DECLARE_DYNAMIC_MUTICAST_DELEGATE(OnOpenRequisted)

in front of the real class .in the C++ we just use the .Broadcast to tell the blueprint we has done something here .so the blueprint can do something whatever it want.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值