ue4 曲线图实现 蓝图_UE4[蓝图]只需一秒!最速实现【二段跳】
我是刘茗,一个专注各种有趣玩法的开发者。
本次带来的是二段跳的教程。
在许多动作游戏中,都有着【二段跳】这样的游戏系统。本文将教大家一个最快实现二段跳的方法。
在Character头文件中,我们可以找到:
最大跳跃次数的定义
/**
* The max number of jumps the character can perform.
* Note that if JumpMaxHoldTime is non zero and StopJumping is not called, the player
* may be able to perform and unlimited number of jumps. Therefore it is usually
* best to call StopJumping() when jump input has ceased (such as a button up event).
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category=Character)
int32 JumpMaxCount;
在Character.cpp中,这个参数会在CanJumpInternal_Implementation函数中被使用。
因此,继承Character类的对象可以修改上述参数来实现
当我们把这个参数改成2的时候……二段跳已完成!
通过修改这个参数,我们还可以实现三段跳、四段跳、各种跳都可以!
看到这里,觉得不够过瘾的朋友们在这里附上……彩蛋
跳跃系统的分析与研究
首先看一下Jump函数:
这里发现bPressedJump被设置成了true,那么这个变量在哪里被使用了呢?在CheckJumpInput函数中。
const bool bDidJump = CanJump() && CharacterMovement->DoJump(bClientUpdating);
在上面这一行代码中,我们发现这里调用了CharacterMovement组件的DoJump函数。
跳转到DoJump函数中
这里对Velocity的Z值进行了赋值,以及设置了运动模式为Falling。
显然——
这个便是Jump功能真正实现函数了。
此外,Character类还提供了一些蓝图接口供开发者定制。
/** Let blueprint know that we were launched */
UFUNCTION(BlueprintImplementableEvent)
void OnLaunched(FVector LaunchVelocity, bool bXYOverride, bool bZOverride);
/** Event fired when the character has just started jumping */
UFUNCTION(BlueprintNativeEvent, Category=Character)
void OnJumped();
在跳跃和落地时,可以添加一些定制化的功能。
最后祝热爱自己事业的朋友们——
人(帅/美)( )大