-
|
I posted this same question under the Stride tag of Stack Exchange Game Development but got no answer in the past 22 days. https://gamedev.stackexchange.com/questions/203338/creating-an-aim-mode-toggle-button-with-virtual-buttons I'm trying to make an "Aim Mode" in Stride for a 3rd person, 2D platformer. The idea is that player presses (and releases) a button that activates Aim Mode, and Aim Mode stays on until player presses the Aim Mode button again. Since the intention is to be usable on keyboard and controller, I implemented the control as a virtual button (currently set to right mouse button and gamepad B), and for the sake of testing I just have Aim Mode be a debug text appearing on screen that says "Aim Mode Active". The problem I have encountered is that Aim Mode will only stay on when one of the buttons is held down, so as soon as the button is released Aim Mode turns off, when the intention is for Aim Mode to stay on until one of the relevant buttons is pressed again. I've been using the Third Person Platformer template as a basis, and had started by trying to add code to the Update method of the "PlayerInput" class, but then decided to try to create a new AimMode class using the code for the Jump method in the "PlayerController" class. Current code that I have for the separate AimMode class (I'm not hard set on AimMode being a separate class, I mainly did that for the sake of organization while trying to figure things out): |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
I don't think you pasted your logic properly, looking at it shows that the text cannot ever toggle off, I ended up testing it just in case and it does toggle on but never turns off - as expected. bool virtualBtnHeld;
public override void Update()
{
var aimModeButton = Input.GetVirtualButton(0, "Aim Mode");
// Note: Gamepad sticks can be a negative value. For this example we only check if the value is higher than 0
if (aimModeButton == 1 && !virtualBtnHeld)
aimModeActive = !aimModeActive;
virtualBtnHeld = aimModeButton == 1;
//and the rest of your logic goes here, so
// if (aimModeActive == true) ...If it still operates in the way you described, you will have to send your project over. |
Beta Was this translation helpful? Give feedback.
I don't think you pasted your logic properly, looking at it shows that the text cannot ever toggle off, I ended up testing it just in case and it does toggle on but never turns off - as expected.
If it does end up operating in the way I just described, then if you want to toggle it on and off by pressing the button you can use the following: