Hi, If you look at the video at the bottom, you can see that the player get’s a “pickup” interaction box when 10 studs from the part…
When the player interacts with it I want the player to automatically walk, no input given from client, literally right on the side of the part using the closest absolute direction, as in If North is closer then the player will walk to the north side of it, and such…
I am not sure what kind-of math I should use to have the player walk towards the box using the closest direction.
Ah okay thanks, not to sure about CFrame yet, not my strong suit. Going to look into it, so I know exactly what I’m doing. I’ll let you know if I need any help.
Wait let me make sure I understand this, so first we make get the position of all the sides and then we get the distance from all of those, and then we walk towards the closest one?
Basically for sides do this, and disregard the top or bottom side… But then leaves me with the issue of so many if statements in one for loop that checks oh if it’s this side, then lets +Size.X or oh it’s this side so we’re going to -Size.Z
I hope that makes sense for what I’m having an issue understanding.
Well this is what I’ve got but the player will go the complete opposite way.
local function GetClosestFace(Player, Part)
local PartFace = {
North = Part.CFrame:PointToObjectSpace(Vector3.new(0, 0, Part.Size.Z/2)),
South = Part.CFrame:PointToObjectSpace(Vector3.new(0, 0, (Part.Size.Z/2)*-1)),
West = Part.CFrame:PointToObjectSpace(Vector3.new(Part.Size.X/2, 0, 0)),
East = Part.CFrame:PointToObjectSpace(Vector3.new((Part.Size.X/2*-1), 0, 0))
}
print(PartFace.North, PartFace.South, PartFace.West, PartFace.East)
local Distances = {
North = Player:DistanceFromCharacter(PartFace.North),
South = Player:DistanceFromCharacter(PartFace.South),
West = Player:DistanceFromCharacter(PartFace.West),
East = Player:DistanceFromCharacter(PartFace.East)
}
print(Distances.North, Distances.South, Distances.West, Distances.East)
local ClosestFace = math.min(Distances.North, Distances.South, Distances.West, Distances.East)
local Face
if ClosestFace == Distances.North then
Face = PartFace["North"]
elseif ClosestFace == Distances.South then
Face = PartFace["South"]
elseif ClosestFace == Distances.West then
Face = PartFace["West"]
elseif ClosestFace == Distances.East then
Face = PartFace["East"]
end
print("Face:", Face)
return Face
end
local function ForcePlayerWalk(Player, Position)
Player.Character.Humanoid:MoveTo(Position)
end
local function GetClosestFace(Player, Part)
local PartFace = {
North = Part.CFrame:ToWorldSpace(CFrame.new(0, 0, Part.Size.Z/2)),
South = Part.CFrame:ToWorldSpace(CFrame.new(0, 0, (Part.Size.Z/2)*-1)),
West = Part.CFrame:ToWorldSpace(CFrame.new(Part.Size.X/2, 0, 0)),
East = Part.CFrame:ToWorldSpace(CFrame.new((Part.Size.X/2*-1), 0, 0))
}
-- Enable to see position of faces.
-- for i,v in pairs(PartFace) do
-- local newpart = Instance.new("Part");
-- newpart.Anchored = true;
-- newpart.CFrame = v;
-- newpart.Size = Vector3.new(1,1,1);
-- newpart.Parent = workspace;
-- end
local Distances = {
North = Player:DistanceFromCharacter(Vector3.new(PartFace.North)),
South = Player:DistanceFromCharacter(Vector3.new(PartFace.South)),
West = Player:DistanceFromCharacter(Vector3.new(PartFace.West)),
East = Player:DistanceFromCharacter(Vector3.new(PartFace.East))
}
local ClosestFace = math.min(Distances.North, Distances.South, Distances.West, Distances.East)
local Face
if ClosestFace == Distances.North then
Face = PartFace["North"]
elseif ClosestFace == Distances.South then
Face = PartFace["South"]
elseif ClosestFace == Distances.West then
Face = PartFace["West"]
elseif ClosestFace == Distances.East then
Face = PartFace["East"]
end
print("Face:", Face)
return Face
end
local function ForcePlayerWalk(Player, Position)
Player.Character.Humanoid:MoveTo(Position)
end
Try this instead. I replaced ToObjectSpace with ToWorldSpace, my bad.
23:02:07.199 - Unable to cast CoordinateFrame to Vector3
23:02:07.199 - Stack Begin
23:02:07.199 - Script 'ServerScriptService.PickupScript', Line 13 - function GetClosestFace
23:02:07.200 - Script 'ServerScriptService.PickupScript', Line 42
23:02:07.200 - Stack End