效果演示

实现思路

惊险闪避触发时机
在敌人攻击动画种,攻击触发前(比如脚踩到地)一小段时间,先开启攻击的检测碰撞,这段时间玩家如果发生触碰同时按下闪避键,就会触发时停效果。

时停效果实现逻辑
先降低游戏时间缩放,然后提高玩家动画播放速率和移动速度,即可实现所有事物变慢,但玩家速度保持不变。

具体实现步骤

惊险闪避触发时机

  • 在敌人招式触发前,添加notify通知:
    image.png

GiantStatusAttack.lua:

-- notify通知触发函数
local notifyBeginFunc = function(name)
    if name == GE.MontageNotifyName.CheckAvoid then
        own.checkAvoid_ = true
        --提前开启碰撞做预警
        own["bp_LeftFootForDamageCol"]:SetCollisionProfileName(GE.CollisionSet.ForDamage, true)

    elseif name == GE.MontageNotifyName.Release then
        --关闭检查
        own["bp_LeftFootForDamageCol"]:SetCollisionProfileName(GE.CollisionSet.NoCollision, true)
        own:CloseAttack_()
        own.checkAvoid_ = false
        释放攻击代码...
    end
end

GiantMonster.lua:

function cls:DamageColBeginOverlap(overlappedComponent, otherActor, otherComp, otherBodyIndex, bFromSweep, sweepResult)
    -- 不是玩家或已碰撞 return
    if otherActor.isPlayer_bp == nil or self.attackedActor_[otherActor] then
        return
    end
    self.attackedActor_[otherActor] = true
    -- 根据类型发送对应通知
    if self.checkAvoid_ then
        GD:Post(self, otherActor, GEVT.CHECK_AVOID, true)
    else
        GD:Post(self, otherActor, GEVT.APPLY_DAMAGE, self, self.aggressivity_bp * self.damageMultipler_, self.impactForce_, false)
    end
end

玩家接收到通知,改变相应状态
Character.lua:

function cls:OnCheckAvoid(isCheck)
    self.checkAvoidToTimeStop_ = isCheck
end

CharacterStatusAvoid.lua:

-- 触发时停
if own.checkAvoidToTimeStop_ then
    own.checkAvoidToTimeStop_ = false
    own.isAvoidTimeStop_ = true
    local timeScale = 0.3
    GF:SetGlobalTimeDilation(timeScale)
    own:SetAnimRate_(1 / timeScale)
    own:SetMaxWalkSpeed_(own.initMaxSpeed_ / timeScale)
    own:DelayCall(3 * timeScale, function()
        own.isAvoidTimeStop_ = false
        GF:SetGlobalTimeDilation(1)
        own:SetAnimRate_(1)
        own:SetMaxWalkSpeed_(own.initMaxSpeed_)
        own.animRate_bp = 1
    end)
end
-- 延迟调用 动画1.3
own:DelayCall(0.7 / own.animRate_bp, function()
    if(own.status_ == Enums.Status.Avoid) then
        own:ChangeNormalStatus_()
    end
end)
最后修改:2022 年 09 月 30 日
如果觉得我的文章对你有用,请随意赞赏