1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:06,000
So one day I received a question how to fix this trouble.

3
00:00:06,000 --> 00:00:09,000
And I looked at the screenshot and I was like, Huh?

4
00:00:10,000 --> 00:00:12,000
Why even this happening?

5
00:00:12,000 --> 00:00:16,000
I was genuinely confused why this might happen at all.

6
00:00:16,000 --> 00:00:20,000
And it took me some time, but I found why.

7
00:00:20,000 --> 00:00:23,000
And now I'm going to explain why this is happening.

8
00:00:23,000 --> 00:00:24,000
And what is it?

9
00:00:25,000 --> 00:00:28,000
I could make same situation in my project.

10
00:00:30,000 --> 00:00:32,000
Happens quite often.

11
00:00:32,000 --> 00:00:34,000
But fix is pretty simple, so don't worry.

12
00:00:34,000 --> 00:00:36,000
First I'll try to show you.

13
00:00:39,000 --> 00:00:40,000
Yeah, I got it.

14
00:00:40,000 --> 00:00:41,000
You see?

15
00:00:42,000 --> 00:00:44,000
So this happened.

16
00:00:47,000 --> 00:00:49,000
Why this happened.

17
00:00:52,000 --> 00:00:53,000
Wait a second.

18
00:00:53,000 --> 00:00:57,000
I'll try to do it again, but I'll pause the game.

19
00:00:59,000 --> 00:01:02,000
So at this point.

20
00:01:03,000 --> 00:01:04,000
The second.

21
00:01:05,000 --> 00:01:06,000
At this point.

22
00:01:06,000 --> 00:01:11,000
There is a platform inside of the Ledge checkbox.

23
00:01:11,000 --> 00:01:12,000
Exactly this one.

24
00:01:12,000 --> 00:01:19,000
So we are not supposed to be able to detect the ledge, if you remember, in the cold.

25
00:01:20,000 --> 00:01:29,000
We said can detect true only when we exit the trigger, which is an our trigger is exactly this one

26
00:01:29,000 --> 00:01:34,000
which is responsible for checking if there is any ground inside.

27
00:01:34,000 --> 00:01:43,000
But we can have this kind of a behavior, this kind of bug, if at the same time we exit platform and

28
00:01:43,000 --> 00:01:46,000
steal, there is another platform inside.

29
00:01:46,000 --> 00:01:48,000
Let me try to.

30
00:01:48,000 --> 00:01:50,000
Find this level part.

31
00:01:52,000 --> 00:01:53,000
So this is one level part.

32
00:01:54,000 --> 00:01:58,000
A canvas canvas is on the way a second.

33
00:01:59,000 --> 00:02:01,000
So this is one level part and this is the second level part.

34
00:02:01,000 --> 00:02:02,000
And.

35
00:02:02,000 --> 00:02:05,000
And as you can see, they overlay in each other.

36
00:02:05,000 --> 00:02:09,000
So there is one platform and there is a second platform here.

37
00:02:09,000 --> 00:02:19,000
So when our box doing check our box, maybe I can change the color so it's more obvious for us.

38
00:02:22,000 --> 00:02:22,000
Look.

39
00:02:23,000 --> 00:02:30,000
When our books did the checking, it exited this platform.

40
00:02:30,000 --> 00:02:34,000
Which is you see, it's even longer in a.

41
00:02:36,000 --> 00:02:36,000
Yeah.

42
00:02:37,000 --> 00:02:38,000
Got it.

43
00:02:38,000 --> 00:02:39,000
I'll do it like this.

44
00:02:39,000 --> 00:02:40,000
Yeah.

45
00:02:42,000 --> 00:02:47,000
So when our box did the check before it entered the alleged climb animation.

46
00:02:50,000 --> 00:02:56,000
It was exiting this platform and it set our can detect to true.

47
00:02:57,000 --> 00:03:02,000
And then at the same time, it entered another trigger over here.

48
00:03:02,000 --> 00:03:03,000
Which set?

49
00:03:03,000 --> 00:03:11,000
Can detect a false, but because it happened within one frame, it was enough time to set players ledge

50
00:03:11,000 --> 00:03:19,000
detected to true because it was detected even though we exited one trigger at the same time there was

51
00:03:19,000 --> 00:03:20,000
another trigger.

52
00:03:20,000 --> 00:03:29,000
So what we need to do is to make sure there is no platforms at all in the trigger before we set can

53
00:03:29,000 --> 00:03:32,000
detect to true over here.

54
00:03:32,000 --> 00:03:34,000
For that, we're going to get access to a box.

55
00:03:34,000 --> 00:03:36,000
Collider we have.

56
00:03:37,000 --> 00:03:38,000
Exactly this box.

57
00:03:38,000 --> 00:03:42,000
Collider So we know the size and position of this box.

58
00:03:42,000 --> 00:03:42,000
Collider.

59
00:03:42,000 --> 00:03:45,000
No matter how we change it, exactly, this box.

60
00:03:45,000 --> 00:03:50,000
Collider So what I'm going to do is go to ledge the ActionScript close all but this.

61
00:03:51,000 --> 00:03:59,000
I'm going to create a private box collider to D, which I will name Box Seed.

62
00:03:59,000 --> 00:04:06,000
As for Box Collider, and I don't want to type any start function, I'll just do return get component

63
00:04:06,000 --> 00:04:09,000
of box Collider to DD.

64
00:04:10,000 --> 00:04:14,000
So now this box seed is this box.

65
00:04:14,000 --> 00:04:16,000
Collider Exactly, this one.

66
00:04:17,000 --> 00:04:24,000
What I'm going to do next is before I set can detect to true, I'm going to check if there is any ground

67
00:04:24,000 --> 00:04:28,000
at all in this trigger.

68
00:04:28,000 --> 00:04:34,000
And we're going to go to on trigger exit to the we're going to create a bunch of colliders that are

69
00:04:34,000 --> 00:04:40,000
going to be that are that are going to be a temporary values collider to the.

70
00:04:42,000 --> 00:04:42,000
Colliders.

71
00:04:42,000 --> 00:04:49,000
And this means we created a colliders just like basically the very same we did here.

72
00:04:49,000 --> 00:04:55,000
But it's going to be used once only inside of this function and trigger exit to DX, and we need to

73
00:04:55,000 --> 00:04:59,000
assign this value and we're going to assign this value because this is array.

74
00:04:59,000 --> 00:05:05,000
We can put a bunch of colliders there and we're going to assign it equals to all of the colliders that

75
00:05:05,000 --> 00:05:10,000
are inside of our trigger, right?

76
00:05:12,000 --> 00:05:13,000
So how are we going to do this?

77
00:05:13,000 --> 00:05:19,000
We're going to do colliders equals to physics to DX, overlap box.

78
00:05:21,000 --> 00:05:22,000
Box all.

79
00:05:24,000 --> 00:05:32,000
Box seed bounce that center box seed that size and angle are going to be zero.

80
00:05:33,000 --> 00:05:36,000
After that, we're going to do check for each collider inside.

81
00:05:36,000 --> 00:05:38,000
So we're going to do for each.

82
00:05:40,000 --> 00:05:44,000
And here we're going to do var Heat in colliders.

83
00:05:45,000 --> 00:05:46,000
Then what are we going to check?

84
00:05:46,000 --> 00:05:52,000
We're going to check if heat means the collider that we hit inside of the box.

85
00:05:53,000 --> 00:06:01,000
Game object get component of platform controller because all of them has this component.

86
00:06:01,000 --> 00:06:03,000
So I'm going to use this one as a check.

87
00:06:04,000 --> 00:06:09,000
If you remember this, the one that responsible for changing colors.

88
00:06:10,000 --> 00:06:11,000
Right.

89
00:06:12,000 --> 00:06:14,000
So if it has this component.

90
00:06:16,000 --> 00:06:17,000
Then we're going to return.

91
00:06:17,000 --> 00:06:21,000
And this means we do in check inside of the box.

92
00:06:21,000 --> 00:06:29,000
Collider Basically, we're doing check of all of the boxes from center point of our box.

93
00:06:29,000 --> 00:06:31,000
Collider This one.

94
00:06:34,000 --> 00:06:38,000
Within the size of our box Collider Again, this one.

95
00:06:38,000 --> 00:06:40,000
So you can change the size of it.

96
00:06:40,000 --> 00:06:41,000
It doesn't matter.

97
00:06:41,000 --> 00:06:43,000
It will always take the size.

98
00:06:44,000 --> 00:06:45,000
We set.

99
00:06:46,000 --> 00:06:50,000
And then we see if there is any object in it.

100
00:06:50,000 --> 00:06:51,000
We're going to check it.

101
00:06:51,000 --> 00:06:57,000
And if this object has platform controller, then we're going to return from this function.

102
00:06:57,000 --> 00:07:02,000
And it means we not going to set can detect a true, pretty simple.

103
00:07:02,000 --> 00:07:08,000
And in this way we're not supposed to meet any similar bug to this again.

104
00:07:09,000 --> 00:07:10,000
Now, let me try this.

105
00:07:10,000 --> 00:07:12,000
I saved my script.

106
00:07:12,000 --> 00:07:20,000
If you remember, I did catch this bug somewhere here because there were two platforms together.

107
00:07:20,000 --> 00:07:21,000
Let me switch off the canvas.

108
00:07:21,000 --> 00:07:25,000
One platform and this is the second one.

109
00:07:25,000 --> 00:07:26,000
So they overlay in each other.

110
00:07:28,000 --> 00:07:28,000
Yeah.

111
00:07:31,000 --> 00:07:33,000
I'll try to find this bug in my game.

112
00:07:35,000 --> 00:07:39,000
I'm sure it won't be there because I did check it before recording.

113
00:07:45,000 --> 00:07:47,000
So no such bug.

114
00:07:52,000 --> 00:07:52,000
Okay.

115
00:07:52,000 --> 00:07:57,000
I hope that explains why that was happening and how to fix it.

116
00:07:57,000 --> 00:07:58,000
Now you know how to fix it.

117
00:07:59,000 --> 00:08:00,000
Maybe I should do it in the first place.

118
00:08:00,000 --> 00:08:05,000
But it was quite, quite difficult to debug this.

119
00:08:05,000 --> 00:08:09,000
I wouldn't face this issue by myself, I guess, unless somebody pointed out.

120
00:08:10,000 --> 00:08:11,000
Thank you for that.

121
00:08:11,000 --> 00:08:14,000
Also, thank you for paying attention.

122
00:08:14,000 --> 00:08:15,000
Finish the course.

123
00:08:15,000 --> 00:08:16,000
Check my other courses.

124
00:08:16,000 --> 00:08:19,000
They're pretty cool and I'll see you in the next one.

