Skip to content
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

Switching to using the new Input System Package #49

Open
XanIves opened this issue May 5, 2024 · 3 comments
Open

Switching to using the new Input System Package #49

XanIves opened this issue May 5, 2024 · 3 comments

Comments

@XanIves
Copy link

XanIves commented May 5, 2024

What I want to do:
Use the new Input System Package (ISP) instead of the legacy Input Manager

What I've tried:
Implemented my own features separately from the Gold Controller, so I'm aware of how the new ISP works with setting up user settings and adding bindings and whatnot.

Since your input system has an EnableAction(int buttonName) method, I tried to call that with an input binding:
image

The input I was attempting to use was Crouch, which I had bound in the ISP to both C and left-stick-click for controllers.

Figured out you're just using a hash of the button name, so I hardcoded the hash and the editor runs without errors when I click the stick, but I get no successful inputs.

Is there a way to actually trigger an input on the controller from outside the script? I don't mind jury-rigging method inputs by hand on an input-by-input basis, I just want to be consistent and not need to worry about having two different input systems.

@Hertzole
Copy link
Owner

Hertzole commented May 5, 2024

EnableAction is for enabling input to be registered at all, basically an on/off switch. From what I understand you want to actually trigger the input, like faking a button press?

@XanIves
Copy link
Author

XanIves commented May 5, 2024

you want to actually trigger the input, like faking a button press?

Exactly, yeah, I'd like to be able to fake button inputs.

@Hertzole
Copy link
Owner

Hertzole commented May 5, 2024

It isn't directly supported but there's a way around it.
You can create your own component that implements IGoldInput. You'll need to implement all the classic input methods, like GetButton, GetButtonDown, etc. Using that you could check if the hash is the same as your action and then return true.

Here's a small example:

public bool doAction; // Set this through other scripts

private readonly int myActionHash = GoldPlayerController.InputNameToHash("My Action");

public bool GetButtonDown(int buttonHash)
{
    if (buttonHash == myActionHash)
    {
        return doAction;
    }

    return false;
}

// do the same for the other actions...

I know this isn't ideal but this is one of the ways to fake input to the controller.

There is another method where you should be able to modify the state of the controller directly. I can't say if all the actions are supported since it's been a while since I used gold player myself. But I know of these two that you can use to get decently far.

GoldPlayerController controller = GetComponent<GoldPlayerController>();
 // Will make the controller jump
controller.Movement.PressedJump = true|false;
// Vector2 with values from 0-1 to make the controller move in a specified direction 
// (relative to the controller direction I think)
controller.Movement.MovementInput = new Vector2(0, 1);
// I think the easiest way to rotate the controller
float strength = 5; // I can't remember how strength works exactly, but I believe it has to do with lerping.
controller.Camera.ForceLook(new Vector3(0, 5, 0), strength);
// To stop force looking
controller.Camera.StopForceLook();

This too isn't ideal, but it works. I used it for a prototype with AI-controlled gold player controllers. They just modified these values directly.

I hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants