You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LookAtTarget("Look At Target", "Look at the block or entity under your crosshair"),
177
-
KeepRotation("Keep Rotation", "Look in the same direction as the camera");
178
-
}
75
+
privateval mode by setting("Mode", Mode.Free, "Freecam movement mode")
76
+
privateval speed by setting("Speed", 0.5, 0.1..1.0, 0.1, "Freecam movement speed", unit ="m/s") { mode ==Mode.Free }
77
+
privateval sprint by setting("Sprint Multiplier", 3.0, 0.1..10.0, 0.1, description ="Set below 1.0 to fly slower on sprint.") { mode ==Mode.Free }
78
+
privateval reach by setting("Reach", 10.0, 1.0..100.0, 1.0, "Freecam reach distance")
79
+
privateval rotateMode by setting("Rotate Mode", FreecamRotationMode.None, "Rotation mode").onValueChange { _, it ->if (it ==FreecamRotationMode.LookAtTarget) mc.crosshairTarget =BlockHitResult.createMissed(Vec3d.ZERO, Direction.UP, BlockPos.ORIGIN) }
80
+
privateval relative by setting("Relative", false, "Moves freecam relative to player position") { mode ==Mode.Free }.onValueChange { _, it ->if (it) lastPlayerPosition = player.pos }
81
+
privateval keepYLevel by setting("Keep Y Level", false, "Don't change the camera y-level on player movement") { mode ==Mode.Free&& relative }
82
+
83
+
// Follow Player settings
84
+
privateval followMaxDistance by setting("String Length", 10.0, 2.0..50.0, 0.5, "Maximum distance before the string pulls the camera", unit ="m") { mode ==Mode.FollowPlayer }
85
+
privateval followTrackPlayer by setting("Track Player", false, "Keeps looking at the followed player") { mode ==Mode.FollowPlayer }
if (mode ==Mode.FollowPlayer&& followTrackPlayer) {
104
+
runSafe {
105
+
findFollowTarget()?.let {
106
+
val vec = it.getLerpedPos(mc.gameRenderer.camera.lastTickProgress).add(.0, it.standingEyeHeight.toDouble(), .0).subtract(lerpPos) // look from lerp pos to target's eye pos
107
+
val yaw =Math.toDegrees(atan2(vec.z, vec.x)) -90.0
108
+
val pitch =-Math.toDegrees(atan2(vec.y, hypot(vec.x, vec.z)))
if (!event.input.handledByBaritone) { // Reset actual input
164
+
event.input.cancel()
165
+
}
166
+
167
+
when (mode) {
168
+
Mode.Free-> {
169
+
// Create new input for freecam
170
+
val input = newMovementInput(assumeBaritone =false, slowdownCheck =false)
171
+
val sprintModifier =if (mc.options.sprintKey.isPressed) sprint else1.0
172
+
val moveDir = calcMoveRad(rotation.yawF, input.roundedForward, input.roundedStrafing)
173
+
var moveVec = movementVector(moveDir, input.verticalMovement) * speed * sprintModifier
174
+
if (!input.isInputting) moveVec *=Vec3d(0.0, 1.0, 0.0)
175
+
// Apply movement
176
+
velocity += moveVec
177
+
velocity *=0.6
178
+
// Update position
179
+
prevPosition = position
180
+
position += velocity
181
+
182
+
if (relative) {
183
+
val delta = player.pos.subtract(lastPlayerPosition)
184
+
position +=if (keepYLevel) Vec3d(delta.x, 0.0, delta.z) else delta
185
+
lastPlayerPosition = player.pos
186
+
}
187
+
}
188
+
189
+
Mode.FollowPlayer-> {
190
+
// Allow manual camera nudges via input
191
+
val input = newMovementInput(assumeBaritone =false, slowdownCheck =false)
192
+
val moveDir = calcMoveRad(rotation.yawF, input.roundedForward, input.roundedStrafing)
193
+
var moveVec = movementVector(moveDir, input.verticalMovement) * speed
194
+
if (!input.isInputting) moveVec *=Vec3d(0.0, 1.0, 0.0)
195
+
// Apply movement
196
+
velocity += moveVec
197
+
velocity *=0.6
198
+
// Update position
199
+
prevPosition = position
200
+
201
+
findFollowTarget()?.let { target ->
202
+
val targetPos2d =Vec2d(target.eyePos.x, target.eyePos.z)
203
+
val cameraPos2d =Vec2d(position.x, position.z)
204
+
val distance2d = targetPos2d.dist(cameraPos2d)
205
+
if (distance2d > followMaxDistance) {
206
+
val excess2d = distance2d - followMaxDistance
207
+
val pullDirection2d =Vec2d(targetPos2d.x - position.x, targetPos2d.y - position.z).normal()
208
+
val pullVec2d = pullDirection2d * excess2d
209
+
position =Vec3d(position.x + pullVec2d.x, position.y, position.z + pullVec2d.y)
210
+
}
211
+
212
+
if (abs(target.eyePos.y - position.y) > followMaxDistance) {
213
+
val excessY = abs(target.eyePos.y - position.y) - followMaxDistance
214
+
val pullDirectionY = sign(target.eyePos.y - position.y)
215
+
position =Vec3d(position.x, position.y + pullDirectionY * excessY, position.z)
216
+
}
217
+
val delta = player.pos.subtract(lastPlayerPosition)
218
+
position +=Vec3d(0.0, delta.y, 0.0)
219
+
}
220
+
position += velocity
221
+
lastPlayerPosition = player.pos
222
+
}
223
+
}
224
+
}
225
+
226
+
listen<RenderEvent.UpdateTarget>({ 1 }) { event ->// Higher priority then RotationManager to run before RotationManager modifies mc.crosshairTarget
227
+
mc.crosshairTarget = rotation.rayCast(reach, lerpPos).orMiss // Can't be null (otherwise mc will spam "Null returned as 'hitResult', this shouldn't happen!")
228
+
mc.crosshairTarget?.let { if (it.type !=HitResult.Type.MISS) event.cancel() }
0 commit comments