【Ark_冷颜】实时角色显示,在ui显示你的角色和动画

效果图和效果视频:

image

我就不解释了,直接放源码了,可自行学习:

--获取服务
local RunService = game:GetService('RunService')
local UserInputService = game:GetService("UserInputService")

--初始化数值
local instance,newRay = Instance.new,Ray.new
local v2,v3,cf,udim2 = Vector2.new,Vector3.new,CFrame.new,UDim2.new
local insert,random,abs	= table.insert,math.random,math.abs


local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()


--基本设置
local ViewPort = script.Parent.ViewportFrame

local Offset = cf(0,1,-6)

--创建相机
local Camera = instance("Camera")
ViewPort.CurrentCamera = Camera

local ValidClasses = {
	["MeshPart"] = true; ["Part"] = true; ["Accoutrement"] = true;
	["Pants"] = true; ["Shirt"] = true;
	["Humanoid"] = true;
}

local function RenderHumanoid(Model, Parent, MainModel)
	local ModelParts = Model:GetDescendants()
	for i=1, #ModelParts do
		local Part = ModelParts[i]

		if ValidClasses[Part.ClassName] then

			local a	= Part.Archivable
			Part.Archivable	= true

			local RenderClone = Part:Clone()
			Part.Archivable	= a

			if Part.ClassName == "MeshPart" or Part.ClassName == "Part" then
				PartUpdater = RunService.Heartbeat:Connect(function() --全局变量,方便取消监听
					if Part then
						RenderClone.CFrame = Part.CFrame
					else
						RenderClone:Destroy()
						PartUpdater:Disconnect()
					end
				end)
			elseif Part:IsA("Accoutrement") then
				PartUpdater = RunService.Heartbeat:Connect(function()
					if Part then
						if RenderClone.Handle then
							RenderClone.Handle.CFrame = Part.Handle.CFrame
						end
					else
						RenderClone:Destroy()
						PartUpdater:Disconnect()
					end
				end)
			elseif Part.ClassName == "Humanoid" then
				--禁用所有状态
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.FallingDown,			false)
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.Running,				false)
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.RunningNoPhysics,	false)
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.Climbing,			false)
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.StrafingNoPhysics,	false)
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.Ragdoll,				false)
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.GettingUp,			false)
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.Jumping,				false)
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.Landed,				false)
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.Flying,				false)
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.Freefall,			false)
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.Seated,				false)
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.PlatformStanding,	false)
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.Dead,				false)
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.Swimming,			false)
				RenderClone:SetStateEnabled(Enum.HumanoidStateType.Physics,				false)
			end

			RenderClone.Parent = Parent
		end 
	end
end


--等待1秒加载
wait(1)


local function Render()
	wait(0.1)
	ViewPort:ClearAllChildren()
	--渲染角色
	local Char = instance("Model")
	Char.Name = ""
	Char.Parent = ViewPort
	RenderHumanoid(Character,Char)
end

--处理变化
Character.DescendantAdded:Connect(Render)
Character.DescendantRemoving:Connect(Render)

--初始化
Render()

CameraUpdater = RunService.Heartbeat:Connect(function()
	if Character.HumanoidRootPart then
		Camera.CFrame =  cf(Character.HumanoidRootPart.CFrame:toWorldSpace(Offset).p, Character.HumanoidRootPart.CFrame.p)
	end
end)
5 个赞

漏了一个,脚本和控件的位置,是放在同一级的
e3458fb77672e6e6a91118139e50b58

1 个赞

嫖到了嫖到了~ :kissing_heart:

ViewPort.CurrentCamera = Camera :sweat_smile:这行一直报错

CurrentCamera is not a valid member of ImageButton “Players.metatun_nft.PlayerGui.Equipment.EquipmentFrameALL.equArea.ViewportFrame” -

关于我们    加入我们    条款    隐私政策
©2021 Roblox Corporation、Roblox、Roblox 标志及 Powering Imagination 是我们在美国及其他国家或地区的注册与未注册商标。
粤ICP备20013629号