mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-12-23 16:32:49 +00:00
better cam input again
This commit is contained in:
parent
4300459c1d
commit
3aec5be028
1 changed files with 30 additions and 24 deletions
|
|
@ -64,6 +64,9 @@ class CameraInput {
|
||||||
prevMouse.y = e.relY;
|
prevMouse.y = e.relY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var accumulator = 0.0;
|
||||||
|
var accumulatedVec = new Vector(0, 0);
|
||||||
|
|
||||||
interactive.onMove = (e) -> {
|
interactive.onMove = (e) -> {
|
||||||
e.propagate = true;
|
e.propagate = true;
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
|
|
@ -79,37 +82,43 @@ class CameraInput {
|
||||||
#if js
|
#if js
|
||||||
scaleFactor = js.Browser.window.devicePixelRatio / Settings.zoomRatio;
|
scaleFactor = js.Browser.window.devicePixelRatio / Settings.zoomRatio;
|
||||||
#end
|
#end
|
||||||
var jumpcam = MarbleGame.instance.touchInput.jumpButton.pressed || MarbleGame.instance.touchInput.powerupButton.pressed;
|
var jumpcam = MarbleGame.instance.touchInput.jumpButton.pressed
|
||||||
|
|| MarbleGame.instance.touchInput.powerupButton.pressed
|
||||||
|
|| MarbleGame.instance.touchInput.blastbutton.pressed;
|
||||||
if (jumpcam) {
|
if (jumpcam) {
|
||||||
scaleFactor /= Settings.touchSettings.buttonJoystickMultiplier;
|
scaleFactor /= Settings.touchSettings.buttonJoystickMultiplier;
|
||||||
}
|
}
|
||||||
if (Math.abs(delta.x) < 0.05)
|
|
||||||
delta.x = 0;
|
|
||||||
if (Math.abs(delta.y) < 0.05)
|
|
||||||
delta.y = 0;
|
|
||||||
|
|
||||||
var inpX = clampInputs(delta.x / scaleFactor);
|
var inpX = delta.x / scaleFactor;
|
||||||
var inpY = clampInputs(delta.y / scaleFactor);
|
var inpY = delta.y / scaleFactor;
|
||||||
|
|
||||||
// Calculate velocity (per second) instead of per-frame delta
|
if (jumpcam) {
|
||||||
var dt = MarbleGame.instance.world.timeState.dt; // Delta time in seconds
|
if (Math.abs(inpX) < 1.3)
|
||||||
var velocityX = inpX / dt;
|
inpX = 0;
|
||||||
var velocityY = inpY / dt;
|
if (Math.abs(inpY) < 1.3)
|
||||||
var velocity = Math.sqrt(velocityX * velocityX + velocityY * velocityY) / 10.0;
|
inpY = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Apply non-linear scaling based on velocity
|
var dt = MarbleGame.instance.world.timeState.dt;
|
||||||
var scaledVelocity = applyNonlinearScale(velocity);
|
accumulator += dt;
|
||||||
var velocityMultiplier = velocity > 0 ? scaledVelocity / velocity : 1.0;
|
|
||||||
|
|
||||||
MarbleGame.instance.world.marble.camera.orbit((inpX * velocityMultiplier), (inpY * velocityMultiplier), true);
|
accumulatedVec.x += inpX;
|
||||||
|
accumulatedVec.y += inpY;
|
||||||
|
|
||||||
|
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)
|
if (inpX != 0)
|
||||||
prevMouse.x = e.relX;
|
prevMouse.x = e.relX;
|
||||||
if (inpY != 0)
|
if (inpY != 0)
|
||||||
prevMouse.y = e.relY;
|
prevMouse.y = e.relY;
|
||||||
|
} else {
|
||||||
prevMouse.x = e.relX;
|
accumulator = 0.0;
|
||||||
prevMouse.y = e.relY;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,15 +132,12 @@ class CameraInput {
|
||||||
|
|
||||||
pressed = false;
|
pressed = false;
|
||||||
this.identifier = -1;
|
this.identifier = -1;
|
||||||
|
accumulator = 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function clampInputs(value:Float) {
|
|
||||||
return Util.clamp(value, -Settings.touchSettings.cameraSwipeExtent, Settings.touchSettings.cameraSwipeExtent);
|
|
||||||
}
|
|
||||||
|
|
||||||
function applyNonlinearScale(value:Float) {
|
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;
|
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