I’m making a grid fighting game and right now im working on the movement i have rays checking for the movement so they dont fall off or go to unneeded areas but my problem is the rotation
it doesnt rotate fully/correctly…
This is calling the movement
local ruth = mygrid.Characters:WaitForChild("Ruth")
local rotation = CFrame.Angles(0, math.rad(180), 0)
local modelCFrame = ruth:GetPrimaryPartCFrame()
ruth:SetPrimaryPartCFrame( modelCFrame * rotation )
--ruth.PrimaryPart.CFrame = ruth.PrimaryPart.CFrame*CFrame.Angles(0, math.rad(180), 0)
wait(2)
repeat
MoveCharacter(ruth.HumanoidRootPart,ruth)
wait(.8)
until stop == true
This is the movement function
local targetReached = false
local movedforward = false
local selectedray = nil
local FrontRay = workspace:Raycast(hrp.Position, hrp.CFrame.LookVector * 3.4)
local RightRay = workspace:Raycast(hrp.Position, hrp.CFrame.RightVector * 3.2)
local LeftRay = workspace:Raycast(hrp.Position, hrp.CFrame.RightVector * -3.2)
if FrontRay then
movedforward = true
selectedray = FrontRay
end
wait()
if movedforward == false then
local random = math.random(1,1)
if random == 1 then
if RightRay then
selectedray = RightRay
end
elseif random == 2 then
if LeftRay then
selectedray = LeftRay
end
end
end
if selectedray then
if selectedray == RightRay then
elseif selectedray == LeftRay then
local rotation = CFrame.Angles(0, math.rad(90), 0)
local modelCFrame = char:GetPrimaryPartCFrame()
char:SetPrimaryPartCFrame( modelCFrame * rotation )
end
local charPos = selectedray.Instance.Position
local cframe = CFrame.lookAt(char.PrimaryPart.Position, charPos)
local modelCFrame = CFrame.fromMatrix(char.PrimaryPart.Position, char.PrimaryPart.CFrame.XVector, cframe.YVector, char.PrimaryPart.CFrame.ZVector)
char:SetPrimaryPartCFrame(modelCFrame)
char.Humanoid:MoveTo(selectedray.Instance.Position)
wait(.45)
if char.PrimaryPart.CFrame ~= selectedray.Instance.Position then
char:MoveTo(selectedray.Instance.Position)
end
end
end
edit: forgot to show you what happens
https://gyazo.com/71334a129cfdb04d2691e5c8a0fc06ac