Unity3d插件 BladeSmith Melee Combat System 武器碰撞检测

unity3d 专栏收录该内容
67 篇文章 1 订阅

作用:武器碰撞检测方案

实现原理
在武器的刀刃上,在整把剑的剑身一条直线上布置多个(8-15个)坐标点,称作标记点.标记点父物体是剑身,播放动画时,标记点也跟着剑挥舞移动.
当播放武器挥舞动画时,就触发预设好的动画事件,开始射线碰撞检测.从这些标记点的上一帧位置到当前帧位置方向发射射线.
当射线检测到碰撞器时,就检查该碰撞器的Tag是否是Enemy .
当剑挥舞结束时,关闭射线检测.
下面是单个标记点代码

    void Start()
    {
        _tempPos = transform.position;
    }
    
     void Update() 
    { 
        if(正在播放武器挥舞动画时)
        {
             _target = null;
            _dir =  transform.position - _tempPos;  //上一帧位置到当前帧位置 方向        
            _dist = Vector3.Distance(transform.position, _tempPos);
            Debug.DrawRay(_tempPos, _dir, Color.white, 0.3f);
            if (Physics.Raycast (_tempPos, _dir, out _hit, _dist, _layers)) {
                _target = _hit.collider.transform;
                _tempPos = transform.position;
                return _target;
            } 
            else 
            {
                _tempPos = transform.position;
                return null;
            }
        }

    }

使用步奏

1.在角色的武器上创建一个空物体挂BS_Maker_Manager.cs
为BS_Maker_Manager.cs面板赋值 
    Stager Animator->拖入角色的animator或者Animation
    Target Tag->Enemy (攻击对象的标签)
    Shield Tag->Shield (护盾的标签,阻挡来袭伤害的物体)
    Damage ->50 (伤害值)
    
2.在BS_Maker_Manager.cs空物体下创建
多个 挂BS_Maker.cs的空物体 ,用这些空物体的坐标点 来标记整把剑的剑身,
(ps:不想标记可以用拖预设物体的)

3.编辑武器挥舞动画开始(EnableMarkers)和结束事件(DisableMarkers).
也就是通过事件来开闭射线检测

4.在角色身上挂 BS_Weapon_Animation_Events.cs 脚本,
为BS_Weapon_Animation_Events.cs面板赋值 把BS_Maker_Manager.cs赋值到变量中.

4.在角色身上挂 BS_Main_Health.cs 脚本,

5.在角色身上挂 BS_Shield.cs 组件 ,面板赋值 Parent Health->BS_Main_Health.cs

==================================================================
上面是攻击方的设置,而敌人的设置
1.碰撞器的Tag->Enemy

2.在敌人物体上挂 BS_Main_Health.cs
为BS_Main_Health.cs面板赋值
sound Source ->在敌人物体上挂 AudioSource 组件 

3.在敌人物体上挂 BS_Shield.cs 组件 ,面板赋值 Parent Health->BS_Main_Health.cs

Synopsis
官方简介
BladeSmith is a movement-based damage applying and recieving system. Sounds fancy,
刀刃是一个基于运动的伤害应用和接收系统。听起来很花哨,
but in short it allows you to set up your own weapons which hit precisely as they move,
但简而言之,它可以让你建立起自己的武器,在它们移动的时候精确打击它们,
will it be through your own animation or scripting. And it's all framerate independent!
它会通过你自己的动画或脚本。而且都是框架独立的!
BladeSmith takes care of the damage dealing part, as well as triggering hurt and death
刀客们负责伤害处理部分,并触发伤害和死亡。
block-stagger events, changing weapon's damage in mid-animation, as well as breathing
阻止交错事件,在动画中改变武器的伤害,以及呼吸
life into the shields of your characters. All you need to bring is your own Animation
生活在你人物的盾牌里。你只需要带你自己的动画
Controller and animations - all the rest is right here.
控制器和动画-其余的都在这里。
As for the documentation, BladeSmith is using the Implemented Documentation method
至于文档,BladeSmith使用的是实现的文档方法
- what it means is simply that everything you need to know about any variable is
-它的意思很简单,你需要知道的关于任何变量的一切都是
written right on it, in a Tooltip. Simply mouse-over any variable to view it's detailed
就写在上面,在工具提示中。只需将鼠标悬停在任何变量上即可查看其详细信息
description, hints and how to use it. Only a few variables may reference this ReadMe
描述、提示以及如何使用它。只有几个变量可以引用这个自述文件
File in more advanced situations.
在更高级的情况下归档。

The Systems
系统
BladeSmith is divided into three sections: Health Systems, Animation Event System and
BladeSmith分为三个部分:血量系统、动画事件系统和
Weapon Systems.
武器系统。
Weapon Systems take care of - you guessed it! - your weapons. It consists of the Weapon
武器系统处理好了-你猜对了!-你的武器。它由武器组成
Marker Manager (the "Soul" of your weapon, which handles all of it's variables) and the
标记管理器(你的武器的“灵魂”,它处理所有的变量)和
Markers (which are used to mark the damage-dealing zones of your weapon (like blades
标记(用于标记武器(如刀刃)的损伤处理区域
or hammerheads).
或者锤头)。
The Animation Events System is a script which should be attached to the object which
动画事件系统是一个脚本,应附加到对象
holds all of the Attack and Shield Animations (like the Mecanim Character wih an
拥有所有的攻击和护盾动画(像魔法人物wih an
Animator attached). We will use these functions to determine what and when your
附有动画师)。我们将使用这些函数来确定
weapon and shield should do what (like enabling Markers, changing damage value etc.)
武器和盾牌应该做什么(如启用标记、改变伤害值等)
The Health Systems are responsible for the pain-recieving side of the party. It consists of
血量系统是主要的受苦方。它包括
the Main Health System (which is the core of the Health Systems), supporting Limb
主要学历系统(是血量系统的核心),支撑肢体
Hitbox system (which can be attached to other colliders to determine precise hitzones of
Hitbox系统(可连接到其他碰撞机上,以确定
the character), Shield system (which manages the shields).
角色),护盾系统(管理盾牌)。

Weapon Systems:
武器系统:
BS_Marker_Manager and BS_Markers
标记管理器和标记
The BS_Marker_Manager is the primary way of making your weapons and attacks deal
标记管理器是使你的武器和攻击交易的主要方式
damage. Attach it to any object which is supposed to be an active Damage Dealer, like a
损坏。把它连接到任何应该是主动损坏经销商的物体上,比如
sword, claws, guillotine traps and so on. You can also attach it to an empty GameObject
剑、爪、断头台陷阱等。你也可以将它附加到一个空的游戏对象上
set as a child of your weapon to keep it clean and tidy in your Hierarchy view.
设置为您的武器的一个孩子,以保持它在您的层次视图整洁。
When the Marker Manager is on the scene, attach the Marker Prefabs (from the BS
当标记管理器在现场时,附加标记预设(从BS
Weapon Marker Systems folder) as children of the Marker Manager and set their hit
武器标记系统文件夹)作为标记管理器的子文件夹并设置其命中
Layer in the inspector. Please keep in mind, that the Marker Manager cannot have any
在检查器中分层。请记住,标记管理器不能有
other children than Markers!
马克以外的其他孩子!
Place your markers along the damage dealing zones (like along your sword or axe blade,
把你的标记放在伤害处理区域(比如你的剑或斧刃,
or around the head yof your hammer), fill in the Marker Manager variables accordingly
或者在锤子头部周围),相应地填写标记管理器变量。
to your design and you're good to go. Your weapon doesn't need any colliders to work -
你的设计很好。你的武器不需要任何对撞机-
it just needs to move in any way to detect hits! The more Markers you place, the more
它只需要以任何方式移动来检测点击!你放置的标记越多,越多
precise the hit check will be, but remember that few hundreds of enabled, active
精确的命中检查将是,但请记住,只有几百个激活的、活动的
Markers on the scene may chip away a few FPS. Make sure to only use as many Markers
现场的标记可能会削掉几帧每秒。确保只使用尽可能多的标记
as necessary. Yet, do not be affraid to add a few more Markers if you require some extra
必要时。但是,如果您需要一些额外的标记,不要害怕添加更多的标记。
precision.
精准度。

Animation Events System:
动画事件系统
BS_Weapon_Animation_Events
武器动画事件
If you plan on using BS Weapon Systems with any kind of animations, it's worth to
如果你计划使用BS武器系统的任何动画,这是值得的。
mention that it's using Animation Events to maintain performance of your Weapons.
提到动画事件是为了维持你的武器
This script should be attached to the object which holds your Attack or Shield
这个脚本应该附着于您的攻击或屏蔽对象。
Animations (will it be Legacy or Mecanim, like the Character with an Animator). After
动画片(将是遗产还是机器,如带有动画的特征)。之后
that, you can use various Animation Events to use functions vital for the
所以,你可以利用各种动画活动来利用重要的功能。
BS_Marker_Manager and BS_Shield. The Events are:
公司经理与BS \ \ shield。The events are:
-DisableMarkers() - Disables the child Markers of the choosen Marker Manager. While
disabled, markers take up almost no performance of CPU or GPU. We will use this
function mostly at the first frame of any attack animation (to make sure that the Markers
在任何攻击动画的第一帧中,函数最多(以确保标记
weren't enabled before) and at the end of the damage-dealing phase of the attack (like
在攻击结束前(例如,在攻击结束前)是不会发生的。
right after the sword swing looses it's speed). This function also resets the Targets' List -
就在剑摇晃失败之后此函数也复制目标列表-
what it means is that after this function was called, everyone who was already hit by any
这是什么意思,在这个函数之后,每个人都被召唤,每个人都被任何人击中。
previous attacks can be hit again. Otherwise any Target which was already hit will be
预先进攻可以再次击中。另一个目标是已经被击中的目标
ignored in next hit checks of the weapon's Markers (so you hit everyone once, no matter
在下一次武器标志的高速检查中被忽略(所以你曾经击中每个人,无所谓)
how slow or fast your sword swing is).
你的剑是多么的慢或快。
-EnableMarkers() - Enables the child markers of the choosen Marker Manager. While
active, your Markers will check if anything was hit during their movement - they use no
活跃的,你的标记会检查在他们的运动中是否有任何东西被击中。
colliders and are framerate independent. We will mostly use this Animation Event on
Colliders and are framerate independent.我们将最充分地利用这个动画片。
the very start of the damage-dealing phase of your attack animation (the moment when
你的攻击动画的损伤清除阶段(当时刻)的非常开始
the sword gains speed during a swing).
剑在摇摆中的速度。
-ClearTargets() - an optional function, which resets the Target's List without turning off
the Markers. Useful if you want to chain the damage-dealing phases without turning off
标记如果你想连锁链损伤处理阶段而不脱离
the markers (like a multiple-spin attack of an axe warrior). Advanced tip: This function
标记(如一个轴战士的多自旋攻击)。高级TIP:此功能
works absolutely the same as calling DisableMarkers() and EnableMarkers() right after
作品绝对一样,如召唤残疾人()和启用标记员()等。
the first one, just with a little better performance.
第一个,只是一个更好的表现。
-CancelStagger() - If you plan on using the Stagger function with a Mecanim Animator,
如果你计划使用一个机械动画家的停滞函数,
keep in mind that after each time the stagger animation kicks in("Stagger" bool is set to
记住,每次停滞动画踢在(“停滞”布尔被设置为
True), it may need to be reverted back to false after it's done. We will call this Animation
事实上,它可能需要在它发生后再回来作弊。我们将称之为动画片
Event at the end of the Stagger Animation.
在停滞动画结束时的事件。
-Stagger() - This function shouldn't be used directly, as it is already called by the
-Stagger() - 此函数不应被间接使用,因为它已经被
Stagger()-This function shouldn't be indirectly used,as it's already called by the
BS_Marker_Manager script, but if you are absolutely sure you know what you're doing -
BS_Marker_Manager script, 但如果你确信你知道自己在做什么
BS \ \ marker \ \ xEC Script,but if you're absolutely sure you know what you're doing-
this function triggers Stagger events.
这个功能触发器停滞事件。
-SetDamage1() ... SetDamage9() - Sets the Damage value of the Marker Manager to
-设置损坏1()…setdamage9()-将标记管理器的损坏值设置为
given value. It is used if some of your attacks are supposed to deal more or less damage
给定值。如果你的一些攻击会造成或多或少的伤害
than others. We will call this Animation Event at the start of each Attack Animation to
比其他人。我们将在每次攻击动画开始时将此动画事件称为
determine how much Damage should the consecutive attack deal. Keep in mind that
确定连续攻击应该造成多大伤害。记住
after the Damage was set, it will not change until another SetDamage was called. You
设置损坏后,直到调用另一个set damage,它才会更改。你
can set up to 9 different damage values for a single weapon.
可以为一件武器设置9个不同的伤害值。
-DisableShieldCollider() and EnableShieldCollider() - These two functions are used to
turn on and off the colliders of a BS_Shield system. We will call EnableShieldCollider()
这两个函数用于打开和关闭BS U屏蔽系统的碰撞器。我们将调用EnableSheldCollider()。
upon rising character's shield and DisableShieldCollider() on lowering it.
当角色的盾牌升起时,在降下时禁用IEldCollider()。
-SetWeapon1MarkerManager() ... SetWeapon10MarkerManager() - These functions are
useful if you've got animations for multiple weapons on one Animator. This function
如果你在一个动画师身上有多个武器的动画,这很有用。这个功能
switches the MarkerManager to another (like between the Marker Manager of a sword
将标记管理器切换到另一个(如在剑的标记管理器之间
and an axe). EnableMarkers, DisableMarkers and other Marker Manager functions will
还有一把斧子)。启用标记、禁用标记和其他标记管理器功能将
be directed to a new Marker Manager. We'll use it at the start of each attack animation,
交给新的标记管理器。我们将在每次攻击动画开始时使用它,
before other animation events, if we've got multiple weapons. Also, don't worry about
在其他动画事件之前,如果我们有多个武器。另外,别担心
the Markers of the previous Manager – they can be automatically disabled upon
上一个管理器的标记–它们可以在
switching Managers.
更换经理。

Health Systems:
血量系统:
BS_Main_Health System
主要血量系统
The Main Health System can be applied on your characters and objects which should be
主要的血量系统可以应用于你的角色和对象
able to recieve Damage of any kind - will it be an Enemy or a destructible element of the
能够承受任何形式的伤害-它是敌人还是
environment, like wood planks. Simply attach it to a character or Object as a new
环境,比如木板。只需将它作为新的附加到角色或对象上
component and fill out the variables. You can also attach any 3D Collider to the same
组成并填写变量。也可以将任何三维碰撞器附加到同一个
object, if you want to use simplified hitzone (like a capsule collider on a character or an
对象,如果要使用简化的HitZone(如角色或
explosive barrel).
炸药桶)。

BS_Limb_Hitbox
BS_肢体_击盒
If you wish to bring more precision into your combat and a single hitbox or hitcapsule is
如果你想在你的战斗中更精确,一个击盒或击胶囊是
not enough, you can use the Limb system to manage hitboxes. Simply, if your character
还不够,您可以使用肢体系统来管理Hitbox。简单地说,如果你的角色
is using children objects as limbs (like in most 3D Character models), just attach precise
使用子对象作为肢体(就像在大多数3D角色模型中一样),只需附加精确的
colliders to all of them and add a Limb Hitbox script to each one (it doesn't need to be
对撞机到它们中的所有对象,并向每个对象添加一个肢体对话框脚本(不需要
humanoid – the limbs can be used in any custom creatures!). In the Limb system
人形——四肢可用于任何定制生物!).在肢体系统中
inspector view assign the Main Health of the character and it can be hit preciesly where
Inspector视图指定角色的主要健康状态,它可以精确命中
you want
你想要的

BS_Shield
BS护盾
BladeSmith allows you also to create your own reactive shields. Attach this script to any
刀剑可以让你创建自己的反应护盾。将此脚本附加到
object which is supposed to block incoming damage (like a shield model, set as child of
被认为可以阻挡来袭伤害的物体(如盾牌模型,被设置为
your character's arm), add up to 5 colliders, set the Edge Spots to determine where are
你角色的手臂),加上5个碰撞器,设置边缘点以确定在哪里。
the colliders' edges (for Advanced Shield Detection) and fill out the variables. Now you
碰撞器的边缘(用于高级屏蔽检测)并填充变量。现在你
can disable and enable shield's colliders on Animation Events (like rising your shield
可以在动画事件中禁用和启用Shield的碰撞器(如升起您的Shield
and lowering it), as well as play blocking animations, giving you the most precise
降低它),以及播放阻止动画,使您获得最精确的
shield-play possible.
可能有护盾间隙。

WORKFLOW
工作流
1. Place the Weapon Marker Manager and weapon Markers on the weapon object.
1.将武器标记管理器和武器标记放在武器对象上。
It can be a simple sword, as well as Rigidbody-driven, blade on a spinning chain
它可以是一把简单的剑,也可以是一把由硬体驱动的旋转链上的刀刃。
– all hit detection will still be framerate independent!
–所有命中检测仍将与帧速率无关!
2. Place the Health and/or Shield script on your characters.
2.第二步。将健康和/或盾牌脚本放在角色上。
3. Bring your Animation Controllers and Animation Clips for attacking, getting
三。带上你的动画控制器和动画剪辑进行攻击,获得
hurt, dying, getting staggered, blocking with your shield etc. [if needed – they
受伤、死亡、蹒跚、用盾牌挡住等[如果需要-他们
are not required]
不需要]
4. Place the Animation Events Script next to all required character Mecanim
第四章。将动画事件脚本放在所有必需的角色Mecanim旁边
Animators or Legacy Animations components (if needed, same as above)
动画师或传统动画组件(如果需要,与上面相同)
5. Set the Animation Events on your Animation Clips or set your weapon to
5.在动画剪辑上设置动画事件或将武器设置为
Constant Damaging.
持续的破坏。
6. Done! Right now, your weapon will register hits and deploy different effects
6.完成!现在,你的武器将注册命中并部署不同的效果
with the Health and Shield Systems, like: spawning blood, playing Sounds,
有了健康和防护系统,比如:产血,演奏声音,
decreaseing targets' health, SendMessaging on Hurt and on Death, playing
降低目标的健康,发送伤害和死亡信息,玩游戏
different animations, getting staggered on shield and wall hits and many, many
不同的动画,在盾牌和墙壁撞击时交错排列,还有很多很多
more!
更多!

 

  • 0
    点赞
  • 0
    评论
  • 2
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2020 CSDN 皮肤主题: 精致技术 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值