What do you want to achieve? i want to achieve a stealth wall hiding system (i guess thats what its called) like the game called Traversal
What is the issue? i’ve been working on it and i did good but the problem is with the CFrames and that it doesn’t rotate the player when he presses the R key. please include screenshots or videos if possible!
What solutions have you tried so far? i did look on devforum and tried but it didn’t work
here is the code:
local player = game.Players.LocalPlayer
local char = player.Character
local uis = game:GetService("UserInputService")
local function Raycast()
local rayCast = RaycastParams.new()
rayCast.FilterType = Enum.RaycastFilterType.Include
rayCast.FilterDescendantsInstances = game.Workspace.Walls:GetChildren()
local rayCastresult = workspace:Raycast(char.HumanoidRootPart.Position, char.HumanoidRootPart.CFrame.LookVector * 3, rayCast)
return rayCastresult
end
--[[game:GetService("RunService").RenderStepped:Connect(function()
coroutine.wrap(Raycast)()
game:GetService("RunService").RenderStepped:Wait()
end)--]]
for i,v in pairs(game.Workspace.Walls:GetChildren()) do
uis.InputBegan:Connect(function(input, psx)
if psx then return end
if input.KeyCode == Enum.KeyCode.R then
local raycast = Raycast()
if raycast.Instance then
if raycast.Instance == v then
local pos = CFrame.new(char.Head.Position)
char.Head.CFrame = pos
--[[local animation = script.Animation
local animationPlay = char.Humanoid:LoadAnimation(animation)
animationPlay:Play()--]]
else
warn("ERROR")
end
end
end
end)
end
I’m not asking for a whole Code. I’m just asking for help.
Number 1 : Use the HumanoidRootPart rather than the head, i understand when you use Roblox’s character loader it sets the primary part to the head. (if your wanting an r6 rig)
What i think you mean by wall hiding system is wall leaning, what i would do is to create a weld between the wall and players root and will update depending on direction keys which would be a-bit difficult because if the camera moves to the edge of the wall and presses forward it would do nothing.
Here’s my rough sketch
local weld = nil -- saving the weld instance
function alignCharacterToWall(raycast:RaycastResult, character:Model) -- aligning the character to the wall
if weld ~= nil then return end
weld = Instance.new('Weld')
local root = character:FindFirstChild('HumanoidRootPart') or character.PrimaryPart
weld.Parent = root
local rayInstance = raycast.Instance
local part0CF = weld.Parent.CFrame
local part1CF = rayInstance.CFrame
weld.Part0 = weld.Parent
weld.Part1 = rayInstance
local directionOffset = raycast.Normal.Unit*0.5
root.CFrame = CFrame.new(raycast.Position+directionOffset) * CFrame.lookAt(root.Position, directionOffset)
weld.C0 = part0CF:inverse() * part1CF
end
function move(weld, isGoingLeft) -- making the character move depending on a boolean
if not weld or not weld:IsA('Weld') then return end
local dir = 1
if isGoingLeft then dir = -1 end
local p:Part
weld.C0 = weld.C0 * CFrame.new(0,0,dir)
end
function disconnect() -- removing the weld
if not weld or not weld:IsA('Weld') then return else weld:Destroy() weld = nil end
end
please reply to me again if this doesnt work right…
function alignCharacterToWall(raycast:RaycastResult, character:Model) -- aligning the character to the wall
if weld ~= nil then return end
weld = Instance.new('Weld')
local root = character:FindFirstChild('HumanoidRootPart') or character.PrimaryPart
weld.Parent = root
local rayInstance = raycast.Instance
local part0CF = weld.Parent.CFrame
local part1CF = rayInstance.CFrame
weld.Part0 = weld.Parent
local directionOffset = raycast.Normal.Unit*0.5
root.CFrame = CFrame.new(raycast.Position+directionOffset) * CFrame.lookAt(root.Position, directionOffset)
weld.C0 = part0CF:inverse() * part1CF
weld.Part1 = rayInstance -- put it here...
end
I apologise but this was the farthest i could go, im not experienced with cframes
function alignCharacterToWall(raycast:RaycastResult, character:Model) -- aligning the character to the wall
if weld ~= nil or not raycast then return end
weld = Instance.new('Weld')
local root = character:FindFirstChild('HumanoidRootPart') or character.PrimaryPart
local humanoid:Humanoid = character:WaitForChild('Humanoid')
humanoid.AutoRotate = false
weld.Parent = root
local rayInstance = raycast.Instance
local part0CF:CFrame = weld.Parent.CFrame
local part1CF:CFrame = rayInstance.CFrame
weld.Part0 = weld.Parent
local directionOffset = raycast.Normal
weld.C0 = part0CF:ToObjectSpace(part1CF)
weld.Part1 = rayInstance
end
i solved it actually. it was simple than what i thought, i basically made a part inside the Character Model to be backwards the HumanoidRootPart and then using CFrame.new(hrp, the part i made) and also it can be tweened which is totally what i wanted.