mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-12-24 17:02:50 +00:00
better cam input again
This commit is contained in:
parent
345560a0c6
commit
77a31c1852
1 changed files with 21 additions and 16 deletions
|
|
@ -68,6 +68,9 @@ class CameraInput {
|
|||
prevMouse.y = e.relY;
|
||||
}
|
||||
|
||||
var accumulator = 0.0;
|
||||
var accumulatedVec = new Vector(0, 0);
|
||||
|
||||
interactive.onMove = (e) -> {
|
||||
e.propagate = true;
|
||||
if (!enabled)
|
||||
|
|
@ -86,12 +89,13 @@ class CameraInput {
|
|||
var jumpcam = MarbleGame.instance.touchInput.jumpButton.pressed
|
||||
|| MarbleGame.instance.touchInput.powerupButton.pressed
|
||||
|| MarbleGame.instance.touchInput.blastbutton.pressed;
|
||||
|
||||
if (jumpcam) {
|
||||
scaleFactor /= Settings.touchSettings.buttonJoystickMultiplier;
|
||||
}
|
||||
|
||||
var inpX = clampInputs(delta.x / scaleFactor);
|
||||
var inpY = clampInputs(delta.y / scaleFactor);
|
||||
var inpX = delta.x / scaleFactor;
|
||||
var inpY = delta.y / scaleFactor;
|
||||
|
||||
if (jumpcam) {
|
||||
if (Math.abs(inpX) < 1.3)
|
||||
|
|
@ -100,22 +104,26 @@ class CameraInput {
|
|||
inpY = 0;
|
||||
}
|
||||
|
||||
// Calculate velocity (per second) instead of per-frame delta
|
||||
var dt = MarbleGame.instance.world.timeState.dt; // Delta time in seconds
|
||||
var velocityX = inpX / dt;
|
||||
var velocityY = inpY / dt;
|
||||
var velocity = Math.sqrt(velocityX * velocityX + velocityY * velocityY) / 10.0;
|
||||
var dt = MarbleGame.instance.world.timeState.dt;
|
||||
accumulator += dt;
|
||||
|
||||
// Apply non-linear scaling based on velocity
|
||||
var scaledVelocity = applyNonlinearScale(velocity);
|
||||
var velocityMultiplier = velocity > 0 ? scaledVelocity / velocity : 1.0;
|
||||
accumulatedVec.x += inpX;
|
||||
accumulatedVec.y += inpY;
|
||||
|
||||
MarbleGame.instance.world.marble.camera.orbit((inpX * velocityMultiplier) / 3, (inpY * velocityMultiplier) / 3, true);
|
||||
if (accumulator >= (1 / 60.0)) {
|
||||
MarbleGame.instance.world.marble.camera.orbit(applyNonlinearScale(accumulatedVec.x) * (1 / 60.0) * 30,
|
||||
applyNonlinearScale(accumulatedVec.y) * (1 / 60.0) * 30, true);
|
||||
accumulator -= (1 / 60.0);
|
||||
accumulatedVec.x = 0;
|
||||
accumulatedVec.y = 0;
|
||||
}
|
||||
|
||||
if (inpX != 0)
|
||||
prevMouse.x = e.relX;
|
||||
if (inpY != 0)
|
||||
prevMouse.y = e.relY;
|
||||
} else {
|
||||
accumulator = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -129,15 +137,12 @@ class CameraInput {
|
|||
|
||||
pressed = false;
|
||||
this.identifier = -1;
|
||||
accumulator = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
function clampInputs(value:Float) {
|
||||
return Util.clamp(value, -Settings.touchSettings.cameraSwipeExtent, Settings.touchSettings.cameraSwipeExtent);
|
||||
}
|
||||
|
||||
function applyNonlinearScale(value:Float) {
|
||||
var clamped = value;
|
||||
var clamped = Util.clamp(value, -Settings.touchSettings.cameraSwipeExtent, Settings.touchSettings.cameraSwipeExtent);
|
||||
return Math.abs(clamped) < 3 ? Math.pow(Math.abs(clamped / 2), 2.7) * (clamped >= 0 ? 1 : -1) : clamped;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue