Skip to content

Commit

Permalink
Merge pull request #184 from candirugame/feat-arrow-keys-for-aiming
Browse files Browse the repository at this point in the history
Feat arrow keys for aiming
  • Loading branch information
AustinJMann authored Nov 29, 2024
2 parents df3cf4c + 4f10af9 commit 380df0a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/core/CommandManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class CommandManager {
public init() {
this.commands.push(new Command('sense', (args: string[]): string => {
if (args[1] == null) {
return "sensitivity is currently " + (SettingsManager.settings.sense * 500);
return "sensitivity is currently " + (SettingsManager.settings.sense);
}
const sense: number = Number(args[1]);
if (Number.isNaN(sense)) {
Expand All @@ -26,7 +26,7 @@ export class CommandManager {
if (sense > 10 || sense <= 0) {
return "sensitivity is not in the valid range of 0 to 10";
}
SettingsManager.settings.sense = sense / 500;
SettingsManager.settings.sense = sense;
SettingsManager.write();
return "sensitivity is now set to " + (sense);
}));
Expand Down
4 changes: 2 additions & 2 deletions src/core/SettingsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class SettingsManager {

public static reset() {
SettingsManager.settings = {
sense: .002,
controllerSense: 4,
sense: 1,
controllerSense: 1,
name: null,
crosshairColor: 'rgb(0,255,255)',
crosshairType: 0,
Expand Down
34 changes: 20 additions & 14 deletions src/input/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ export class InputHandler {
if (this.gamepadInputs.leftTrigger > .5) this.aim = true;
if (this.gamepadInputs.rightTrigger > .5) this.shoot = true;
const aimAdjust = this.calculateAimAssist();
this.gamepadEuler.y -= this.gamepadInputs.rightJoyX * SettingsManager.settings.controllerSense * deltaTime * aimAdjust;
this.gamepadEuler.x -= this.gamepadInputs.rightJoyY * SettingsManager.settings.controllerSense * deltaTime * aimAdjust;
this.gamepadEuler.y -= this.gamepadInputs.rightJoyX * SettingsManager.settings.controllerSense * deltaTime * aimAdjust * 4;
this.gamepadEuler.x -= this.gamepadInputs.rightJoyY * SettingsManager.settings.controllerSense * deltaTime * aimAdjust * 4;
this.gamepadEuler.x = Math.max(-Math.PI / 2, Math.min(Math.PI / 2, this.gamepadEuler.x));
this.localPlayer.lookQuaternion.setFromEuler(this.gamepadEuler);
}
Expand All @@ -121,29 +121,29 @@ export class InputHandler {
this.inputX += deltaTimeAcceleration * this.touchJoyX;
this.inputZ += deltaTimeAcceleration * this.touchJoyY;

//touch look controls

const touchSensitivity = 0.03; // Adjust sensitivity as needed
this.gamepadEuler.setFromQuaternion(this.localPlayer.lookQuaternion);
this.gamepadEuler.y -= this.touchLookX * touchSensitivity;
this.gamepadEuler.x -= this.touchLookY * touchSensitivity;
this.gamepadEuler.x = Math.max(-Math.PI / 2, Math.min(Math.PI / 2, this.gamepadEuler.x));
this.localPlayer.lookQuaternion.setFromEuler(this.gamepadEuler);

//touch buttons





if (!this.localPlayer.chatActive && !this.nameSettingActive) {
if (this.getKey('w')) this.inputZ -= deltaTimeAcceleration;
if (this.getKey('s')) this.inputZ += deltaTimeAcceleration;
if (this.getKey('a')) this.inputX -= deltaTimeAcceleration;
if (this.getKey('d')) this.inputX += deltaTimeAcceleration;
const aimAdjust = this.calculateAimAssist();
if (this.getKey('arrowright')) this.gamepadEuler.y -= SettingsManager.settings.controllerSense * deltaTime * aimAdjust * 4;
if (this.getKey('arrowleft')) this.gamepadEuler.y += SettingsManager.settings.controllerSense * deltaTime * aimAdjust * 4;
if (this.getKey('arrowup')) this.gamepadEuler.x += SettingsManager.settings.controllerSense * deltaTime * aimAdjust * 4;
if (this.getKey('arrowdown')) this.gamepadEuler.x -= SettingsManager.settings.controllerSense * deltaTime * aimAdjust * 4;
if (this.getKey(' ')) this.jump = true;

}

this.gamepadEuler.y -= this.touchLookX * touchSensitivity;
this.gamepadEuler.x -= this.touchLookY * touchSensitivity;
this.gamepadEuler.x = Math.max(-Math.PI / 2, Math.min(Math.PI / 2, this.gamepadEuler.x));
this.localPlayer.lookQuaternion.setFromEuler(this.gamepadEuler);

switch (this.inputZ - oldInputZ) {
case 0:
this.inputZ = InputHandler.approachZero(this.inputZ, deltaTimeAcceleration);
Expand Down Expand Up @@ -282,7 +282,13 @@ export class InputHandler {
}

private calculateAimAssist(): number {
if ((Math.abs(this.gamepadInputs.rightJoyX) >= .1 || Math.abs(this.gamepadInputs.rightJoyY) >= .1)) {
if(this.gamepad) {
if ((Math.abs(this.gamepadInputs.rightJoyX) >= .1 || Math.abs(this.gamepadInputs.rightJoyY) >= .1)) {
if (this.renderer.getPlayerSpheresInCrosshairWithWalls().length > 0) {
return .5;
}
}
} else if (this.getKey('arrowup') || this.getKey('arrowdown') || this.getKey('arrowleft') || this.getKey('arrowright')) {
if (this.renderer.getPlayerSpheresInCrosshairWithWalls().length > 0) {
return .5;
}
Expand Down
4 changes: 2 additions & 2 deletions src/input/PointerLockControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export class PointerLockControls extends THREE.EventDispatcher<PointerLockContro
const euler = new THREE.Euler(0, 0, 0, 'YXZ');
euler.setFromQuaternion(this.localPlayer.lookQuaternion);

euler.y -= movementX * SettingsManager.settings.sense;
euler.x -= movementY * SettingsManager.settings.sense;
euler.y -= movementX * SettingsManager.settings.sense * .002;
euler.x -= movementY * SettingsManager.settings.sense * .002;

euler.x = Math.max(-Math.PI / 2, Math.min(Math.PI / 2, euler.x));

Expand Down

0 comments on commit 380df0a

Please sign in to comment.