You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Hey, I’m trying to create a hitbox for which is just in front of my player using region.
The problem is my maths. Right now it works, but the hitbox (pink) is like this
when it should be like this
local region = Region3.new(char.HumanoidRootPart.Position - Vector3.new(2,2.5,0), char.HumanoidRootPart.Position + Vector3.new(2,2.5,3))
I have tried changing the values in here for a while now to move the hitbox, but I just can’t get it to work. So how can I fix this?
note: I’m unable to change the region3’s CFrame, as it is a read-only value.
Well, to get the bottom left corner you can do this by making the position relative to the orientation of the Character using CFrames:
local characterCFrame = char.HumanoidRootPart.CFrame
local cornerPosition1 = (characterCFrame*CFrame.new(-Vector3.new(2,2.5,0))).Position
local cornerPosition2 = (characterCFrame*CFrame.new(Vector3.new(2,2.5,3))).Position
local region = Region3.new(cornerPosition1,cornerPosition2)
I’m not sure it’ll work but that’s the gist of CFrame multiplication. However you will find that the region3 won’t be rotated like the second image as Region3’s cannot be rotated especially if the character is facing diagonally. To solve this you can use the RotatedRegion3 Module.
Hmm, honestly I would play around adjust the values more, however, this time use a region3 visualizer to debug the problem since it’s hard to tell looking at the gif provided by using the following code:
local Debris = game.Debris--get the service
local regionVisualizer = Instance.new("Part")
regionVisualizer.Name = "rV"
regionVisualizer.Anchored = true
regionVisualizer.CanCollide = false
regionVisualizer.Size = region3.Size
regionVisualizer.CFrame = region3.CFrame
regionVisualizer.Parent = workspace
If you want to move it forward, you can add the humanoid root part’s CFrame.LookVector * distance you want it to move forward (maybe about 3) to each of the corner Vector3s.
I would suggest not using a region3 for a hit box by the way. They can’t spin around or anything. You might have a specific use case, like finding all the parts somewhat close to the character then running checkers and stuff.