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

Why is the movement on my object so jittery?

Asked by 7 years ago
function hover()
    if model ~= nil then
    model:MoveTo(Vector3.new((mouse.hit.p.X) - (mouse.hit.p.X%1),Base.Position.Y,(mouse.hit.p.Z) - (mouse.hit.p.Z%1)))
    else
--      print "No object"
    end




end

thats the section of my code where movement happens.. its supposed to move one stud at a time which works but whenever i try to move it at a diagonal path it jitters and isnt smooth... im just trying to make movement the way the dragger tool and the insert tool do it... non jittery and smooth

1 answer

Log in to vote
1
Answered by 7 years ago

There's a few things I would change here.

Personally, I would not use MoveTo for the model. I recommend you set the Model's PrimaryPart property to any part (preferably a part closest to the center, or maybe the base) and move the part using :SetPrimaryPartCFrame. I also recommend you use math.floor while incrementing by 0.5 on each dimension to get to the nearest stud. Here's my code:

function hover()
    if model ~= nil then
        model:SetPrimaryPartCFrame(CFrame.new(math.floor(mouse.Hit.p.X + 0.5), Base.Position.Y, math.floor(mouse.Hit.p.Z + 0.5)))
    end
end

Eventually you may add a map to your game, so you might want to change Base.Position.Y to math.floor(mouse.Hit.p.Y + 0.5) so your part isn't always restrained to the baseplate.

0
I would like it to be constantly constrained to the y axis... And i feel like thats the reason why its all jittery i will try math.floor tho :) Chaserox 62 — 7y
Ad

Answer this question