# Model starts spinning like crazy?

So ive been making my own building game for 1 - 3 weeks now. And i recently learn the basics of Object and World space… But i ran into a pretty annoying problem

Ive been lookng around and trying to fix this myself but sadly failed… So i decided to see if i can get some help here?

Anyways when i implemented them into my module code the models just start spinning like crazyyyyy.

Heres a quick video to give you a better understanding

Heres my current way of moving the model:

– // Convert to object space

``````local function Convert_Cf(Part, Pos, Grid) -- Part = Plot, Pos = Ray position, Grid = 4
local Object_Pos = Part.CFrame:ToObjectSpace(Pos)

local Cf = Calc_Cf(Object_Pos, Grid)

local World_Cf = Part.CFrame:ToWorldSpace(Cf)

return World_Cf
end
``````

– // Code that calculates the CFrame

``````function Calc_Cf(Vector, Grid) -- Vector = Ray position, Grid = 4
return CFrame.new(
math.floor(Vector.X / Grid + 0.5) * Grid,
math.floor(Vector.Y / Grid + 0.5) * Grid,
math.floor(Vector.Z / Grid + 0.5) * Grid
)
end
``````

– // Code that moves the model around

``````Move = Run.RenderStepped:Connect(function()

local P, S = ray(M, {Plr.Character, game.Workspace.Terrain}) -- P = Ray position, S = Surface normal

if P and S then

local SURFACE = P + (S * (Current_Obj.PrimaryPart.Size * .5))

local Cf = Convert_Cf(Plot.Parent.PLOT, CFrame.new(P + SURFACE), Grid)

Current_Obj:SetPrimaryPartCFrame(Cf * Rot)

end
end)
``````

I’m not too sure, but I think it’s the fact you’ve got `(Cf * Rot)` in the bottom line.
Why not include the Rot in the local `Cf =` part, without multiplying it by `Rot`?

Also you can now round numbers without having to use `math.floor(Vector.X / Grid + 0.5) * Grid`.
Just use `math.round(Vector.X / Grid) * Grid`.

1 Like

Sorry if this sounds really dumb . But what do you mean with “inlcude the rot”?

I tried multiplying the “Calc_Cf” cframe with the rotation which fixed the spinning problem. But then my rotate function wouldnt work

Just here to say that i fixed this. I didnt have to multiply any cframe + For the rotation problem i changed it to:

``````function Rotate(Name, State, Input)
if Name == "Rotate" and State == Enum.UserInputState.Begin then
Current_obj.PrimaryPart.CFrame = Current_obj.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(90), 0)
end
end
``````

(:

1 Like