What I’m trying to do is have it so when I move the model it doesn’t rotate, it should stay in its original rotation. and as mentioned in my previous reply, I need NewPos + Normal * 15
otherwise the model goes into the ground
Your code should look like this:
Model:SetPrimaryPartCFrame(
CFrame.new(NewPos) *
CFrame.Angles(0, math.rad(YRot), 0) *
CFrame.new(0, Model.PrimaryPart.Size.Y / 2, 0)
)
Ok, I was so excited cause that worked, kinda. It fixes the whole rotation glitch, but now when I move the model up along the walls it doesnt rotate on the wall. It just stays upright (which isn’t what I want)
The model should rotate along with the wall, which is what it did when I had this
Model:SetPrimaryPartCFrame(
CFrame.new(NewPos, NewPos + Normal * 15) *
CFrame.Angles(-math.rad(90), math.rad(yRot), 0) *
CFrame.new(0, Model.PrimaryPart.Size.Y / 2, 0)
)
Video with old code to show it should work moving up the wall
Oh sorry! If you just want to move to model you could do something like this:
local oldRot = Model.PrimaryPart.CFrame-Model.PrimaryPart.Position
local UnitRay = Camera:ScreenPointToRay(Mouse.X, Mouse.Y, 1)
local NewRay = Ray.new(UnitRay.Origin, UnitRay.Direction * 1000)
local Hit, Pos, Normal = workspace:FindPartOnRayWithIgnoreList(NewRay, {Model, Player.Character})
local PosX = math.floor((Pos.X / 2) + 0.5) * 2
local PosY = Pos.Y
local PosZ = math.floor((Pos.Z / 2) + 0.5) * 2
local NewPos = Vector3.new(PosX, PosY, PosZ)
Model:SetPrimaryPartCFrame(
oldRot + NewPos
)
Started with:
Ended with: (after moving it)
I need the model to move up along walls tho too (info in my last post)
Note I got my code from here
And it seemed to work from there, so not sure why it doesn’t work for me
This should do it!
Model:SetPrimaryPartCFrame(
(CFrame.new(Vector3.new(0,0,0),Normal) + NewPos) * oldRot
)
Worked for me atleast, rotated on walls too.
If the rotation is incorrect, swap CFrame.new(Vector3.new(0,0,0),Normal)
and oldRot
The rotation was off with that, plus the model would appear half in the floor, and then swapping those 2 around cause this error
Model:SetPrimaryPartCFrame(
(CFrame.new(Vector3.new(0,0,0),Normal) + NewPos) * oldRot
)
And then this is the error when I switch those 2 values you said to switch
[attempt to multiply a Vector3 with an incompatible value type or nil]
@Rocky28447 has had the closest solution so far with
Model:SetPrimaryPartCFrame(
CFrame.new(NewPos) *
CFrame.Angles(0, math.rad(Rotation), 0) *
CFrame.new(0, Model.PrimaryPart.Size.Y / 2, 0)
)
This literally so close to what works, just doesn’t rotate on the walls, which is what
NewPos + Normal * 15
was for, but adding that screws with the Y rotation when moving
I don’t know why you got that error with swapping those two but this is what I did and I fixed the things you mentioned:
local oldRot = Model.PrimaryPart.CFrame-Model.PrimaryPart.Position--literally the exact same as CFrame:ToOrientation()
-- Move the model
local UnitRay = workspace.CurrentCamera:ScreenPointToRay(Mouse.X, Mouse.Y, 1)
local NewRay = Ray.new(UnitRay.Origin, UnitRay.Direction * 1000)
local Hit, Pos, Normal = workspace:FindPartOnRayWithIgnoreList(NewRay, {Model, Player.Character})
local PosX = math.floor((Pos.X / 2) + 0.5) * 2
local PosY = Pos.Y
local PosZ = math.floor((Pos.Z / 2) + 0.5) * 2
local NewPos = Vector3.new(PosX, PosY, PosZ)
Model:SetPrimaryPartCFrame(
(oldRot + NewPos) * CFrame.new(Vector3.new(0,0,0),Normal*15) * CFrame.Angles(-math.rad(90),0,0) * CFrame.new(0,Model.PrimaryPart.Size.Y/2,0)
)
Ended:
Still not working
This just brought back the main problem I was having with the models rotation being reset back to 0.
I think I’m just gonna stick with @Rocky28447 code, and just try to figure out to get to work along walls.
I just tested @jaschutte’s code and it works perfectly fine. Are you sure you copied it correctly?
Edit: Aside from model rotations that is.
local oldRot = Model.PrimaryPart.CFrame-Model.PrimaryPart.Position--literally the exact same as CFrame:ToOrientation()
Mouse.Move:Connect(function()
if IsMoving then
local UnitRay = workspace.CurrentCamera:ScreenPointToRay(Mouse.X, Mouse.Y, 1)
local NewRay = Ray.new(UnitRay.Origin, UnitRay.Direction * 1000)
local Hit, Pos, Normal = workspace:FindPartOnRayWithIgnoreList(NewRay, {Model, Player.Character})
local PosX = math.floor((Pos.X / 2) + 0.5) * 2
local PosY = Pos.Y
local PosZ = math.floor((Pos.Z / 2) + 0.5) * 2
local NewPos = Vector3.new(PosX, PosY, PosZ)
Model:SetPrimaryPartCFrame(
(oldRot + NewPos) * CFrame.new(Vector3.new(0,0,0),Normal*15) * CFrame.Angles(-math.rad(90),0,0) * CFrame.new(0,Model.PrimaryPart.Size.Y/2,0)
)
end
end)
And the model is still going into the walls. And ye, the models rotation gets reset whenever I move it
I think I know what happened, what is the current orientation of the model may I ask?
The starter orientation must be 0,0,0
What I suggest is this:
Model:SetPrimaryPartCFrame(ModelPos * ROTATION)
then:
Model.PrimaryPart.CFrame = CFrame.new(Model.PrimaryPart.Position)
This way the model is rotated but the hitbox isn’t.
What I mean is, replace your model rotation function with this:
function setCFRotation(R) --NOTE: This *set* the rotation, so calling setCFRotation(45) will won't increase the rotation but set it.
Model:SetPrimaryPartCFrame(CFrame.new(0,0,0)*CFrame.Angles(0,math.rad(R),0)) --rotates the model
Model.PrimaryPart.CFrame = CFrame.new(0,0,0) --resets the primarypart cf
end
Then use the movement code I’ve sent,
Once all of that is don’t should work.
Didn’t change anything and now when I rotate the model just disappears
Probably because of CFrame.new(0,0,0)
replace that with: CFrame.new(Model.PrimaryPart.Position)
EDIT: I’ll just send you the file I used for this. CFrames can get really confusing really quickly lol. I wish you luck! Baseplate.rbxl (16.3 KB)
The problem I see with your place tho is since your part is just a cube you can’t actually tell if the parts being rotated weirdly. Plus there’s no rotation
In my code you should see:
function rotateCF()
Model:SetPrimaryPartCFrame(CFrame.new(0,0,0)*CFrame.Angles(0,.707,0))
Model.PrimaryPart.CFrame = CFrame.new(0,0,0)
end
If you call that if will rotate by 45 degrees.
Or replace it with this:
function rotateCF(R)
Model:SetPrimaryPartCFrame(CFrame.new(0,0,0)*CFrame.Angles(0,R,0))
Model.PrimaryPart.CFrame = CFrame.new(0,0,0)
end
rotateCF(math.deg(45))
And you should see rotation now.
Either way, just transferred your code exact from your script to my script and the model still gets put inside the wall at weird rotations
Go to your model, check the orientation.
if it isn’t this
then change it to that.
That should also fix the model getting sinked in.
I’m trying to find a fix why the model collapses into itself.