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.
What I've tried so far:
- moving the "If" statement starting at "if (aimModeButton == 1)" from the Update method to the Start method
- moving "bool aimModeActive = false;" into Update method
- adding "aimModeActive == false;" to If condition and setting "aimModeActive = !aimModeActive"
- setting "aimModeActive = !aimModeActive" within If statement without changing If condition
I'm now at a loss of what to do next, since Stride doesn't have a dedicated "Is Virtual Button Pressed" method like it does with keyboard buttons, and I'm fairly new to C# (and programming in general) as is.
Relevant code below:
private bool aimModeActive = false;
public override void Start()
{
Input.VirtualButtonConfigSet = Input.VirtualButtonConfigSet ?? new VirtualButtonConfigSet();
var aimMouseRight = new VirtualButtonBinding("Aim Mode", VirtualButton.Mouse.Right);
var aimGamePadB = new VirtualButtonBinding("Aim Mode", VirtualButton.GamePad.B);
var virtualButtonAimMode = new VirtualButtonConfig
{
aimMouseRight,
aimGamePadB
};
Input.VirtualButtonConfigSet.Add(virtualButtonAimMode);
}
public override void Update()
{
{
var aimModeButton = Input.GetVirtualButton(0, "Aim Mode");
if (aimModeButton == 1)
{
aimModeActive = true;
if (aimModeActive == true)
{
DebugText.Print("Aim Mode Active", new Int2(400, 400));
}
}
}
}