pug6_4
(pug)
February 19, 2022, 11:56am
#1
Hello, i’m making a parkour system and it was working pretty well untill i ran into a problem i don’t know how to fix.
I believe this happens because i’m using the size so it’ll be different depending on rotation.
Anyways, here’s my code.
local RayPos = ray.Position
local RayInstance = ray.Instance
local Pos1 = RayPos
local Y = RayInstance.Position.Y + RayInstance.Size.Y/2
local Size = RayInstance.Size
local MaxCF = RayInstance.CFrame * CFrame.new(Size.X/2,Size.Y/2,Size.Z/2)
local MinCF = RayInstance.CFrame * CFrame.new(-Size.X/2,Size.Y/2,-Size.Z/2)
local Pos2 = Vector3.new(math.clamp(RayPos.X,MinCF.X,MaxCF.X),Y,math.clamp(RayPos.Z,MinCF.Z,MaxCF.Z))
local Brick = Instance.new("Part")
Brick.Anchored = true
Brick.CanCollide = false
Brick.Color = Color3.new(1, 0, 0)
Brick.Size = Vector3.new(0.2,0.2,0.2)
Brick.Position = Pos2
Brick.Parent = workspace
Anyone know how i can fix this?
1 Like
Olinator21
(Olinator21)
February 19, 2022, 12:02pm
#2
Can you elaborate on what it is that the system is supposed to do?
pug6_4
(pug)
February 19, 2022, 12:06pm
#3
Well, it’s supposed to find the corners of the part so i can restrain the rayposition, and then create a way for the character to climb up when they’re close to a ledge.
This drawing is horrible, but hopefully you’ll understand what i mean.
BaconKral
(Zephyria)
February 19, 2022, 12:10pm
#4
You don’t have to find it, you can just put a block to it’s corners and you can use magnitude
BaconKral
(Zephyria)
February 19, 2022, 12:11pm
#5
And the error is probably because max is smaller than the min.
Olinator21
(Olinator21)
February 19, 2022, 12:12pm
#6
Can I see line 54 on the main local script, because that’s where the error is coming from. However I can guess that you have put the Max value lower than the Min value therefore creating an error. And I’m assuming that if you rotate a part this can make the error
pug6_4
(pug)
February 19, 2022, 12:13pm
#7
Yes, that’s the problem. I’m not sure as to what i should do since i have to find the Max X coordinate inside the part and the Max Z coordinate, and vice verse.
local Pos2 = Vector3.new(math.clamp(RayPos.X,MinCF.X,MaxCF.X),Y,math.clamp(RayPos.Z,MinCF.Z,MaxCF.Z))
BaconKral
(Zephyria)
February 19, 2022, 12:14pm
#8
Have you placed them correctly into the ()?
pug6_4
(pug)
February 19, 2022, 12:15pm
#9
Yes, it’s because of the rotation. I believe i might have to use the lookvectors of the part to correctly find it, although i’m unsure.
Olinator21
(Olinator21)
February 19, 2022, 12:16pm
#10
Can I see how you are getting the max and min and x
pug6_4
(pug)
February 19, 2022, 12:17pm
#11
local MaxCF = RayInstance.CFrame * CFrame.new(Size.X/2,Size.Y/2,Size.Z/2)
local MinCF = RayInstance.CFrame * CFrame.new(-Size.X/2,Size.Y/2,-Size.Z/2)
Olinator21
(Olinator21)
February 19, 2022, 12:29pm
#12
I’m not familiar with Rays, however you will probably have to also calculate the rotation of the part and then calculate that into the rayinstance
pug6_4
(pug)
February 19, 2022, 12:32pm
#13
if MinCF.X > MaxCF.X and MinCF.Z < MaxCF.Z then
Pos2 = Vector3.new(math.clamp(RayPos.X,MaxCF.X,MinCF.X),Y,math.clamp(RayPos.Z,MinCF.Z,MaxCF.Z))
elseif MinCF.Z > MaxCF.Z and MinCF.X < MaxCF.X then
Pos2 = Vector3.new(math.clamp(RayPos.X,MinCF.X,MaxCF.X),Y,math.clamp(RayPos.Z,MaxCF.Z,MinCF.Z))
elseif MinCF.Z > MaxCF.Z and MinCF.X > MaxCF.X then
Pos2 = Vector3.new(math.clamp(RayPos.X,MaxCF.X,MinCF.X),Y,math.clamp(RayPos.Z,MaxCF.Z,MinCF.Z))
else
Pos2 = Vector3.new(math.clamp(RayPos.X,MinCF.X,MaxCF.X),Y,math.clamp(RayPos.Z,MinCF.Z,MaxCF.Z))
end
Ended up on this, it works but i feel it might error in a specific condition.
1 Like
pug6_4
(pug)
February 19, 2022, 12:35pm
#14
Also, CFrames already do that. It was just because at a specific rotation the X,'s or Z’s would be flipped, causing one of them to be more than the max.
1 Like
your parkour system is very nice I was wondering what type of game you’re making and if the parkour system is going to be released on #resources:community-resources ?
pug6_4
(pug)
March 2, 2022, 2:38pm
#16
I might release it but it’s being used for a game currently