用途:面向 Roblox 开发,整理角色(Character)与动画相关的实现要点,包括角色结构、生成、生命值伤害、外观、动画播放、补间与工具。
主要能力:角色是含 Humanoid、HumanoidRootPart、R15 部件与 Animate LocalScript 的 Model,用 character:PivotTo(cframe) 移动;默认值在 Studio 的 Avatar Settings 与 StarterPlayer 配置。自定义角色可在 StarterPlayer 放名为 StarterCharacter 的 Model;逐玩家生成需设 Players.CharacterAutoLoads = false 后调用 player:LoadCharacterAsync()(非 Async 版已弃用)。死亡/重生会销毁重建角色,逻辑应绑定 CharacterAdded。生命值用 humanoid:TakeDamage(amount)(受 ForceField 影响),绕过则用 Health -= amount;可设 MaxHealth、监听 Died。外观用 Players:GetHumanoidDescriptionFromUserIdAsync 与 humanoid:ApplyDescriptionAsync(非 Async 版已弃用),或用 LoadCharacterWithHumanoidDescriptionAsync 直接生成。动画经 Animator:LoadAnimation 加载(Humanoid:LoadAnimation 已弃用),设置 Priority、Looped,用 GetMarkerReachedSignal 监听标记,Play(fadeTime) 播放;每个 Animator 只加载一次并复用 track。Tween 用 TweenService:Create 补间锚定部件或 UI,服务器补间会逐帧复制导致卡顿,纯视觉运动应在客户端做。Tool 放在 StarterPack/Backpack,含 Handle 部件,Equipped/Unequipped/Activated 在客户端与服务器触发,需在服务器校验。
使用方式与限制:客户端设置的 WalkSpeed/JumpHeight 易被利用,须在服务器限制或采用服务器权威。动画资源须归体验所有者所有或经资源权限共享,否则线上静默失败。humanoid:MoveTo 用于 NPC 行走,8 秒超时需重发。角色控制器库(CCL,require("@rbx/AvatarAbilities"))为 beta,需在 Beta Features 与 Avatar Settings 中启用,API 可能变动。相关技能:roblox-npc-ai、roblox-physics、roblox-input、roblox-security、roblox-game-systems。