You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? I want to award a player with 2 or 3 points depending on how far away they are from the basketball hoop.
What is the issue?
As you can probably see a 3pt-line on all sides is different in length, so I can’t just get the magnitude of the player and the hoop, because then I would have to listen for a length that would ultimately be equal on every side.
What solutions have you tried so far?
I tried detecting if the player was either infront or behind the 3pt-line, and used PointToObjectSpace. However, since it’s one big union if you’re infront of the 3pt-line it will register it as behind the 3pt-line.
I then tried shooting a ray ontop of the player’s head, and detecting if the brick above them was named either 2 or 3, but this seems very hacky and will mess with the system as I move forward into development.
Maybe put an invisible union behind the 2 point line, then check if the player is touching the 2 point union when he scores using GetTouchingParts(). If the player isn’t touching it it’s a three pointer, but if he is it’s a two pointer.
You could outline the areas with a boundary made with parts facing inwards which determine how many points one gets from scoring then iterate through and convert the RootPart’s position to be relative to each boundary part and check if the RootPart’s position is in front of all the parts meaning the RootPart is within the boundaries.
I think it’s similar to what you tried here. Though, make sure to use parts to outline the boundaries and that they face inwards.
Example:
function WithinBoundary(BoundaryFolder, Position)
for i, boundaryPart in pairs(BoundaryFolder:GetChildren()) do
local RelativeCFrame = boundaryPart.CFrame:inverse() * CFrame.new(Position)
if RelativeCFrame.Z > 0 then -- negative is in front, positive is behind
return false
end
end
return true
end
I thought about this, but I thought since I would have multiple courts running at the same time it would be intensive? I’m not really sure if this is the most efficient way, any concerns in this regard?
If I were you, I would just make the 3pt line the same length on every side. I don’t think players would even notice a difference and you can easily use magnitude to get the distance if you do it this way. If this isn’t an option you like, your better off using the dot product with multiple parts.
This won’t be a problem as long as you sort the boundaries by which court the player is playing on, and you won’t really run this on every heartbeat either.
[color=#FFC900]Note: using :GetTouchingParts and .Touched is much more intensive than the method I proposed and more inaccurate as it would count even if you only touch the boundary with the tip of your hand or foot.[/color]
You can also make it so if gets the position from the rootpart to the goal.
By doing that you gonna have to make a humanoid statement. For Example.
If you want it to print: print(RootPart.Position)
I might as well comment what I actually did since someone bumped this, but I just fired 2 rays downward from my root part to look for parts that said “2” which is what covered the inside area of the 3 point line, and the actual name of the parts that made up the 3 point line. This works extremely well.