Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Mouse moving object in z direction?

Asked by
xEiffel 280 Moderation Voter
5 years ago

Hi, I'm struggling to understand how to do this, basically how do I make it so that an object follows your mouse but doesn't move the object in the (x,y) positions only the (z) position? This is my attempted script:

-- Player
local Player = game.Players.LocalPlayer
local Character = workspace:WaitForChild(Player.Name)
local Mouse = Player:GetMouse()

-- Services
local Storage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

-- Content
local Gear = Storage:FindFirstChild("Gear")
local Models = Gear:FindFirstChild("Models")

local Killer = {}

local Model = Models:FindFirstChild("Killer"):WaitForChild("BearTrap"):Clone()
Model.Parent = workspace

RunService.RenderStepped:Connect(function()
    local MousePos = Mouse.Hit
    Model:SetPrimaryPartCFrame(Character.HumanoidRootPart.CFrame * CFrame.new(0, -0.55, Mouse.Hit.p))
end)

Here is the focus:

RunService.RenderStepped:Connect(function()
    local MousePos = Mouse.Hit
    Model:SetPrimaryPartCFrame(Character.HumanoidRootPart.CFrame * CFrame.new(0, -0.55, Mouse.Hit.p))
end)

I have tried this and it doesn't work, I have tried other ways and it errors. Is there anyone that can help? If you don't understand I can try to provide examples of what I want it to be like.

Thanks.

0
cant you do mouse.Hit.Z? theking48989987 2147 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
RunService.RenderStepped:Connect(function()
    local MousePos = Mouse.Hit
    Model:SetPrimaryPartCFrame(Character.HumanoidRootPart.CFrame * CFrame.new(Mouse.Hit.p, Mouse.Hit.p - 0.55, Mouse.Hit.p))
end)

This is my theory: the position is not precisely set and when you multiply by only one axis, it will only move in one direction

0
Thanks! I'll try this. xEiffel 280 — 5y
Ad

Answer this question