-
What do you want to achieve?
How can i move the player towards the “Climb” Part (is there a way to convert the raycast’s position to CFrame because i want to move the player closer to the wall using tweenservice ) and reset its rotation to face the wall that i found with raycast. -
What is the issue?
just dont know how to change the position to cframe and reset the rotation of the player to face the wall. -
What solutions have you tried so far?
i tried to use the rayresult’s position but then the character’s humanoid root part was going to the place without the rest of the body and ive been trying to find a solution for so long.
Here’s my code (btw only using a local script for now )
LocalScript:
--services
local CAS = game:GetService("ContextActionService")
local UIS=game:GetService("UserInputService")
local players=game:GetService("Players")
local TweenService=game:GetService("TweenService")
--end of services
--useful variables for later
local debounce = false
local playerfound = false
local hum = script.Parent.Humanoid
local FREEZE = "freezeMovement"
local val=nil
local char = script.Parent
local pp =false
local dd = false
local deb = true
--end of useful variables for later
-- animation
local humanoid = char:WaitForChild("Humanoid")
local vaultanim = script.Parent.vault
local vaultanimtrack = humanoid.Animator:LoadAnimation(vaultanim)
local vaultanim2 = script.Parent.vault2
local vaultanimtrack2 = humanoid.Animator:LoadAnimation(vaultanim2)
local vaultanim3 = script.Parent.vault3
local vaultanimtrack3 = humanoid.Animator:LoadAnimation(vaultanim3)
local Animate = script.Parent:WaitForChild("Animate")
local walkanim = Animate.walk.WalkAnim
local walkanimtrack = humanoid.Animator:LoadAnimation(walkanim)
--end of animation
function ended(input)
if input.KeyCode==Enum.KeyCode.Space and dd == true and deb == true then
dd = false
deb = false
deb = true
end
end
UIS.InputEnded:Connect(ended)
local raycastDistance = 4
while wait() do
local raycastParams = RaycastParams.new()
raycastParams.IgnoreWater = true
raycastParams.FilterDescendantsInstances = {script.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local rayResult = workspace:Raycast(char.HumanoidRootPart.Position, char.HumanoidRootPart.CFrame.LookVector * 3000, raycastParams)
if rayResult then
local position = rayResult.Position
local distance = (char.HumanoidRootPart.Position - position).Magnitude
if distance < raycastDistance then
if rayResult.Instance.Name == "Climb" then
val = rayResult.Instance
dd = true
end
end
else
game.Players.LocalPlayer.PlayerGui.found.Value = false
dd = false
print("notfound")
end
end
(EDIT)
how to fix the rotation so it always faces the part
here’s my code
--services
local CAS = game:GetService("ContextActionService")
local UIS=game:GetService("UserInputService")
local players=game:GetService("Players")
local TweenService=game:GetService("TweenService")
--end of services
--useful variables for later
local debounce = false
local playerfound = false
local hum = script.Parent.Humanoid
local FREEZE = "freezeMovement"
local val=nil
local pos=nil
local char = script.Parent
local pp =false
local dd = false
local deb = true
--end of useful variables for later
-- animation
local humanoid = char:WaitForChild("Humanoid")
local vaultanim = script.Parent.vault
local vaultanimtrack = humanoid.Animator:LoadAnimation(vaultanim)
local vaultanim2 = script.Parent.vault2
local vaultanimtrack2 = humanoid.Animator:LoadAnimation(vaultanim2)
local vaultanim3 = script.Parent.vault3
local vaultanimtrack3 = humanoid.Animator:LoadAnimation(vaultanim3)
local Animate = script.Parent:WaitForChild("Animate")
local walkanim = Animate.walk.WalkAnim
local walkanimtrack = humanoid.Animator:LoadAnimation(walkanim)
--end of animation
function ended(input)
if input.KeyCode==Enum.KeyCode.Space and dd == true and deb == true then
dd = false
deb = false
local GoalCF = pos * CFrame.Angles(0,math.rad(180),0)
local humrroot = char.PrimaryPart
local huminf = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In)
local humtop1 = TweenService:Create(humrroot, huminf, {
CFrame = GoalCF * CFrame.new(-2,5,0)
})
char.HumanoidRootPart.Anchored = true
humtop1:Play()
wait(1)
char.HumanoidRootPart.Anchored = false
deb = true
end
end
UIS.InputEnded:Connect(ended)
local raycastDistance = 10
while wait() do
local raycastParams = RaycastParams.new()
raycastParams.IgnoreWater = true
raycastParams.FilterDescendantsInstances = {script.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local rayResult = workspace:Raycast(char.HumanoidRootPart.Position, char.HumanoidRootPart.CFrame.LookVector * 3000, raycastParams)
if rayResult then
-- print(rayResult2.Instance.Name)
local position = rayResult.Position
local distance = (char.HumanoidRootPart.Position - position).Magnitude
if distance < raycastDistance then
if rayResult.Instance.Name == "Climb" then
pos = CFrame.new(position,position + CFrame.new(char.HumanoidRootPart.Position, char.HumanoidRootPart.CFrame.LookVector).LookVector)
val = rayResult.Instance
dd = true
end
end
else
game.Players.LocalPlayer.PlayerGui.found.Value = false
dd = false
print("notfound")
end
end