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

Model Moving rotates upwards with mouse?

Asked by
yoshi8080 445 Moderation Voter
8 years ago

I made this model which does rotate in the direction of the mouse, but once the mouse moves towards the center of the model, it tilts upwards or downwards. The script works, but moving upwards or downwards isn't what I intended the script to do

It's a local script

Cannon = game.Workspace.Cannon
player = game.Players.LocalPlayer
mouse = player:GetMouse()

local prev_mouse_hit 

    mouse.Button1Up:connect(function()
end)

    mouse.Button1Down:connect(function()
end)

    mouse.Move:connect(function()
        if mouse.Hit.p ~= prev_mouse_hit then
            Cannon:SetPrimaryPartCFrame(CFrame.new(Cannon.PrimaryPart.Position,Vector3.new(mouse.Hit.p.x,0,mouse.Hit.p.z))) 
            prev_mouse_hit = mouse.Hit.p
    end
end)

1 answer

Log in to vote
0
Answered by
theCJarmy7 1293 Moderation Voter
8 years ago

Ok, the issue was that the model would look at the area right near it, and it's position would change a little.

mouse.Move:connect(function()
    if mouse.Hit.p ~= prev_mouse_hit then
        local vect = Cannon.PrimaryPart.Position
        Cannon:SetPrimaryPartCFrame(CFrame.new(Vector3.new(vect.X,0,vect.Z),Vector3.new(mouse.Hit.p.x,0,mouse.Hit.p.z)))
        prev_mouse_hit = mouse.Hit.p
--also, why the prev_mouse_hit thing?
--this works because it forces the y on rotation and position to be 0, but if you need the y to be different, then just make it like 10 or something
    end
end)
Ad

Answer this question