1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//! What each blocked sweep of a slide met, in the order it met it:
//! [`SlideContact`], recorded by
//! [`CharacterController::move_and_slide_into`](super::CharacterController::move_and_slide_into)
//! and
//! [`CharacterController::move_lying_into`](super::CharacterController::move_lying_into).
use DVec3;
use crateColliderId;
/// One sweep of a [`move_and_slide_into`] or [`move_lying_into`] that met
/// something, and what the slide did about it.
///
/// A move is a loop of straight sweeps. Each one that hits a collider is one
/// contact, in the order the loop met them, so the list holds exactly
/// [`MoveOutcome::slides`] entries, or [`LyingMoveOutcome::slides`] for a
/// lying move. **Every hit is recorded, not only the ones that stopped the
/// character**: a floor a falling character lands on, a ceiling a jump
/// grazes, a wall it was already touching and moving along or away from —
/// each of those still costs a sweep and redirects what is left, and each can
/// be followed by a later wall within the same move.
///
/// # Fractions are distance along one straight sweep, never time
///
/// [`fraction`](Self::fraction) is the share of [`requested`](Self::requested)
/// covered before the capsule touched the collider, in `[0, 1]`. For a
/// [`clearance_only`](Self::clearance_only) contact, it is where the skin
/// envelope touched instead. It measures
/// distance along that one straight segment, from where the capsule stood when
/// the sweep began.
///
/// It is **not** a share of the tick, and not of the move either:
///
/// * Each sweep after the first starts from where the last one left the
/// capsule and asks for what the last contact left over
/// ([`remaining`](Self::remaining)), so its fraction is a share of that
/// remainder alone.
/// * The controller is kinematic and the move is a straight displacement the
/// caller has already integrated. A caller that integrates an acceleration —
/// gravity, an air-control curve — and hands over the chord of that arc gets
/// fractions along the chord. Where the arc itself would have touched the
/// collider, and when, is a different point at a different time, and nothing
/// here can recover it.
/// * Summing the displacement the contacts removed and dividing by the
/// requested length does not give elapsed time either: the slide redirects
/// the motion at each contact, so distance lost to one plane is not time
/// spent.
///
/// A caller that needs times along a curved path has to sweep the path in
/// pieces short enough that a chord stands in for the arc, and own that
/// approximation.
///
/// # How the fields fit together
///
/// For a physical contact, the capsule keeps a [`skin_width`] off the surface it met, measured along
/// [`normal`](Self::normal). With `direction = requested.normalize()`,
/// `along = fraction * |requested|` and `closing = -direction · normal`, a
/// sweep that did not step up and touched from further than that
/// (`along * closing > skin_width`) stops a skin width short across the
/// normal: `applied = direction * (along - skin_width / closing)`. One that
/// touched from no further — [`started_inside`](Self::started_inside), or
/// already that near — backs off along the normal instead:
/// `applied = normal * (skin_width - max(along * closing, 0))`, or not at all
/// (`applied` zero) when that back-off is too short to count as a move, so a
/// capsule already a skin width off the surface, to within rounding, stays
/// exactly where it is. A grounded
/// lying body measures both against a wall's normal made level, the plane its
/// slide clips against, rather than the leaning one recorded here. The next
/// contact's `requested` is this one's `remaining`, exactly.
///
/// A clearance-only contact already includes the skin in the swept radius.
/// It advances by `requested * fraction`, without subtracting another skin,
/// or backs out of the envelope's initial overlap. Only incoming clearance
/// contacts are recorded; the envelope does not block motion along or away
/// from a surface.
///
/// [`move_and_slide_into`]: super::CharacterController::move_and_slide_into
/// [`move_lying_into`]: super::CharacterController::move_lying_into
/// [`MoveOutcome::slides`]: super::MoveOutcome::slides
/// [`LyingMoveOutcome::slides`]: super::LyingMoveOutcome::slides
/// [`skin_width`]: super::CharacterConfig::skin_width