-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Controller joysticks #416
base: master
Are you sure you want to change the base?
Controller joysticks #416
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very incomplete, has no buttons support, has bad practices and needs more refinement.
@@ -8,6 +8,7 @@ import { ItemType, type ItemDefinition } from "@common/utils/objectDefinitions"; | |||
import { Vec } from "@common/utils/vector"; | |||
import $ from "jquery"; | |||
import nipplejs, { type JoystickOutputData } from "nipplejs"; | |||
import * as PIXI from "pixi.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do not import everything from pixijs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, now it only imports ticker
@@ -342,6 +343,50 @@ export class InputManager { | |||
shootOnRelease = false; | |||
}); | |||
} | |||
const ticker = new PIXI.Ticker(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Game
class's pixi ticker
const ticker = new PIXI.Ticker(); | ||
ticker.stop(); | ||
ticker.add(() => { | ||
const gamepads = navigator.getGamepads(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you use Game
's pixi ticker, put this into its own method
const gamepads = navigator.getGamepads(); | ||
if (gamepads[0]) { | ||
const leftJoystickMoving = gamepads[0].axes[0] !== 0 || gamepads[0].axes[1] !== 0; | ||
const rightJoystickMoving = gamepads[0].axes[2] !== 0 || gamepads[0].axes[3] !== 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rest in peace stick drift controllers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps there could be a sensitivity setting to adjust when the JoystickMoving vars are considered true
ticker.stop(); | ||
ticker.add(() => { | ||
const gamepads = navigator.getGamepads(); | ||
if (gamepads[0]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allow players to select their gamepad
const rightJoystickMoving = gamepads[0].axes[2] !== 0 || gamepads[0].axes[3] !== 0; | ||
// const rightJoystickDistance = Math.sqrt(gamepads[0].axes[2] * gamepads[0].axes[2] + gamepads[0].axes[3] * gamepads[0].axes[3]); | ||
// distance formula for stuff like throwables, USAS-12, and M590M | ||
if (leftJoystickMoving) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably best to allow players to configure which joystick to use for what
this.turning = true; | ||
const activePlayer = game.activePlayer; | ||
if (game.console.getBuiltInCVar("cv_responsive_rotation") && !game.gameOver && game.activePlayer) { | ||
game.activePlayer.container.rotation = this.rotation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't there a better way to do this in the Player
class?
const ticker = new PIXI.Ticker(); | ||
ticker.stop(); | ||
ticker.add(() => { | ||
const gamepads = navigator.getGamepads(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you really need to call this method every frame, is it required?
fix: only imported ticker instead of all of pixi.js
@@ -8,7 +8,7 @@ import { ItemType, type ItemDefinition } from "@common/utils/objectDefinitions"; | |||
import { Vec } from "@common/utils/vector"; | |||
import $ from "jquery"; | |||
import nipplejs, { type JoystickOutputData } from "nipplejs"; | |||
import * as PIXI from "pixi.js"; | |||
import { Ticker } from "pixi.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is still wrong, use the Game
update method
*Not using requestAnimationFrame anymore