File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
components/joystick/include Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -156,8 +156,15 @@ class Joystick : public BaseComponent {
156
156
position_.x (0 );
157
157
position_.y (0 );
158
158
} else if (magnitude > 1 .0f ) {
159
- // otherwise, we need to clamp the vector to be within the unit circle
159
+ // if it's outside the unit circle, then normalize the vector so that
160
+ // it's on the unit circle
160
161
position_ = position_.normalized ();
162
+ } else {
163
+ // otherwise we should scale the vector so that it's 0 on the edge of
164
+ // the deadzone and 1 on the edge of the unit circle
165
+ const float magnitude_range = 1 .0f - center_deadzone_radius_;
166
+ const float scale = (magnitude - center_deadzone_radius_) / magnitude_range;
167
+ position_ *= scale;
161
168
}
162
169
}
163
170
}
You can’t perform that action at this time.
0 commit comments