Mail.ruПочтаМой МирОдноклассникиВКонтактеИгрыЗнакомстваНовостиКалендарьОблакоЗаметкиВсе проекты

Lua | Помогите исправить скрипт

Vasya Shalun Ученик (85), закрыт 5 дней назад
Это скрипт на клик трейсер, но он не работает как надо
Идея: когда ты кликаешь лкм, появляется трейсер который напревлен туда, куда ты смотрел

Проблема: трейсер постоянно идет только в 1 сторону




Сам скрипт
  
local userInputService = game:GetService("UserInputService")
local workspace = game:GetService("Workspace")


local function createTracer(startPosition, direction)

local tracer = Instance.new("Part")
tracer.Size = Vector3.new(0.2, 0.2, (startPosition - direction).Magnitude)
tracer.Position = startPosition + (direction - startPosition) / 2
tracer.Anchored = true
tracer.CanCollide = false
tracer.BrickColor = BrickColor.new("Bright violet")
tracer.Material = Enum.Material.Neon
tracer.Parent = workspace


game:GetService("Debris"):AddItem(tracer, 2)
end

userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end


if input.UserInputType == Enum.UserInputType.MouseButton1 then
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local startPos = player.Character.HumanoidRootPart.Position
local direction = mouse.Hit.p

createTracer(startPos, direction)
end
end)
Лучший ответ
Кирилл Маноев Ученик (117) 1 месяц назад
задай корректную ориентацию

local UserInputService = game:GetService("UserInputService")

local Workspace = game:GetService("Workspace")

local function createTracer(startPosition, endPosition)

local directionVector = (endPosition - startPosition)

local distance = directionVector.Magnitude





local tracer = Instance.new("Part")

tracer.Size = Vector3.new(0.2, 0.2, distance)

tracer.Anchored = true

tracer.CanCollide = false

tracer.BrickColor = BrickColor.new("Bright violet")

tracer.Material = Enum.Material.Neon





tracer.CFrame = CFrame.lookAt(

startPosition + directionVector/2,

endPosition

)



tracer.Parent = Workspace

game:GetService("Debris"):AddItem(tracer, 0.5)

end

UserInputService.InputBegan:Connect(function(input, gameProcessed)

if gameProcessed or input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end



local player = game.Players.LocalPlayer

if not player.Character then return end



local rootPart = player.Character:FindFirstChild("HumanoidRootPart")

local mouse = player:GetMouse()



if rootPart and mouse then

createTracer(rootPart.Position, mouse.Hit.Position)

end

end)
Vasya ShalunУченик (85) 1 месяц назад
Спасибо большое!
Остальные ответы
Похожие вопросы