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

How would you move objects with your mouse?

Asked by 5 years ago

So, I've been trying to work on a horror game that follows similar mechanics to Amnesia: The Dark Decent.

Atm I've been trying to work on a door and drawer system, such as where you click on the door to open it, and you move your mouse to show how much you want it open. This follows the same with a drawer opening system, where you click, hold, and move your mouse to position how much you want it open, or closed.

I've been having trouble with this, as I haven't been able to get this to work properly, and I also haven't been able to get a max rotation value so the door/drawer doesn't go past its limits.

This is the code I have so far, which I don't think is even the right way to do it:

local Mouse = game.Players.LocalPlayer:GetMouse()

local klik = false
local prev_mousehit

Mouse.Button1Up:connect(function()
    klik = false
end)

Mouse.Button1Down:connect(function()
    klik = true
end)

Mouse.Move:connect(function()
    if klik == true and Mouse.Hit.p ~= prev_mousehit then
        game.Workspace.Model.Main.CFrame = game.Workspace.Model.Main.CFrame *        
  CFrame.Angles(0, -Mouse.X / 80, 0)
        prev_mousehit = Mouse.Hit.p
    end
end)
0
Sorry, don't have time to write up an answer but I would just use the movement delta of the mouse. AZDev 590 — 5y
0
Take the initial 2D position of the mouse and subtract it from the 2D position of the mouse whenever the mouse moves. AZDev 590 — 5y
0
Normalize your delta and use that as an Alpha value to calculate how far the door should open. Use the lerp method on the door for the easiest results. AZDev 590 — 5y
0
I'll try this out once I finish my Homework, thank you. Razorboots 5 — 5y
0
Is there anyway I can do this without using InputService? Razorboots 5 — 5y

Answer this question