Player character collides with part when moving 30 studs

  1. player collides with parts

  2. i making player char going 30 studts and when it moces 30 studs it can go into the part heres a video about it:

here the move script

ReplicatedStorage.Events.RemoteEvents.MoveChar.OnServerEvent:Connect(function(plr)
	local character = plr.Character or plr.CharacterAdded:Wait()
	if character then
		local position = character.HumanoidRootPart.Position
		local direction = character.HumanoidRootPart.CFrame.LookVector
		local targetPosition = position + (direction * 30)
		character.HumanoidRootPart.CFrame = CFrame.new(targetPosition)
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

You should raycast instead of just setting the character’s CFrame 30 studs forward

1 Like

can u give an example script of it pls

Okay, I guess. I hope this work since I literally haven’t tested it yet :

local character = plr.Character or plr.CharacterAdded:Wait()

if character then
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	raycastParams.FilterDescendantsInstances = {character:GetChildren()}

	local Raycast = workspace:Raycast(character.HumanoidRootPart.Position, character.HumanoidRootPart.CFrame.LookVector * 30)
	
	if Raycast ~= nil then
		character.HumanoidRootPart.Position = Raycast.Position
	else
		character.HumanoidRootPart.Position = character.HumanoidRootPart.CFrame.LookVector * 30
	end
end
1 Like

it happens like this

I think I know how to fix this one

local character = plr.Character or plr.CharacterAdded:Wait()

if character then
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	raycastParams.FilterDescendantsInstances = {character:GetChildren()}

	local Raycast = workspace:Raycast(character.HumanoidRootPart.Position, character.HumanoidRootPart.CFrame.LookVector * 30)
	
	if Raycast ~= nil then
		character:PivotTo(CFrame.new(Raycast.Position))
	else
		character:PivotTo(CFrame.new(HumanoidRootPart.CFrame.LookVector * 30))
	end
end
1 Like

it not works

Try this :

local character = plr.Character or plr.CharacterAdded:Wait()

if character then
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	raycastParams.FilterDescendantsInstances = {character:GetChildren()}

	local Raycast = workspace:Raycast(character.HumanoidRootPart.Position, character.HumanoidRootPart.CFrame.LookVector * 30)
	
	if Raycast ~= nil then
		character:PivotTo(CFrame.new(Raycast.Position))
	else
		character:PivotTo(HumanoidRootPart.CFrame * CFrame.new(30,0,0))
	end
end

I am half asleep right now, so I may cannot find the solution in my current state.

1 Like

it not works ok no problem if u cant find i wait for someone or i try to find it my self i do not know too much about raycast lol

Thanks for understanding my current state, finally some rest after some time.

1 Like

What you’re doing is teleporting the player, obviously this will cause issues.
Here is what you could do:

  1. RayCast in front of the player, to see until when the player would reach a part, then move them to the end of the RayCast instead of 30 studs forwards.
  2. Push the player forwards with BodyVelocity, BodyForce though these 2 are deprecated. So instead use LinearVelocity.

Also your script is complicating something simple:

local position = character.HumanoidRootPart.Position
local direction = character.HumanoidRootPart.CFrame.LookVector
local targetPosition = position + (direction * 30)
character.HumanoidRootPart.CFrame = CFrame.new(targetPosition)

Can be replaced with:

local root = character:FindFirstChild("HumanoidRootPart")
root.CFrame = root.CFrame * CFrame.new(Vector3.new(0, 0, 30))
-- make sure this is the correct direction, it's either the X or Z direction 
-- and also make sure if it has to be negative or not. 
1 Like

can u give an example of it please i am really bad at raycasting i gonna learn it soon as possiable

Honestly raycasting is not my expertise. Though if I am right the issue you’re currently facing has to do with you moving the player incorrectly with

CFrame.new(Vector3.new(30, 0, 0)

Instead of

CFrame.new(Vector3.new(0, 0, 30)) 

Also

would not work correctly because it’s an array inside an array, instead:

raycastParams.FilterDescendantsInstances = {character}

would work
Lastly he forgot to insert the raycastParams inside the rayCast

This all should fix @BirdieGoodMan’s script:

Which would look like:

local character = plr.Character or plr.CharacterAdded:Wait()

if character then
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	raycastParams.FilterDescendantsInstances = {character}

	local Raycast = workspace:Raycast(character.HumanoidRootPart.Position, character.HumanoidRootPart.CFrame.LookVector * 30, raycastParams)
	
	if Raycast ~= nil then
		character:PivotTo(CFrame.new(Raycast.Position))
	else
		character:PivotTo(HumanoidRootPart.CFrame * CFrame.new(Vector3.new(0,0,30)))
	end
end

if I am not mistaken this should work correctly.

Note, make sure to mess around with the CFrame being correctly aimed, either X, -X, Z or -Z.

1 Like

it takes me to back

i fixed it sorry

How am I supposed to fix it when I’m half asleep.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.