#ChatGPT 4, PowerQuest and Direct Movement via Gamepad

1 messages · Page 1 of 1 (latest)

ruby girder
#

PowerQuest is a 2D point-and-click adventure game engine for Unity. Direct character movement using a gamepad is not a built-in feature, but you can implement it using the Unity Input System and modifying the existing PowerQuest scripts. Here's a step-by-step guide on how to do that:

Install the Unity Input System package
Go to Window > Package Manager, search for "Input System" and click Install.

Set up the Input System
Go to Edit > Project Settings > Input > Input System Package and enable the "New Input System" option. This will disable the old Unity input system and activate the new one. You'll need to restart the Unity editor.

Create a new Input Action Asset
Right-click in your Assets folder > Create > Input Actions. Name it "GamepadActions". Double click to open it in the Input Actions editor. Create a new Action Map called "CharacterControl". Inside this map, create a new action called "Move" and set its type to "Value" and control type to "Vector2". Bind it to "Gamepad > Left Stick".

Save the Input Action Asset
Click "Save Asset" in the Input Actions editor.

Modify the PowerQuest scripts
First, you need to modify the "QuestScript.cs" script. Add the following namespaces at the top of the file:

#
using PowerTools;
#

Then, add a reference to your "GamepadActions" asset, and create a new variable to hold the character movement input.

#
private Vector2 m_characterMovement;
#

In the "OnEnable()" method, enable the input action and subscribe to the performed and canceled events:

#
moveAction.performed += OnMovePerformed;
moveAction.canceled += OnMoveCanceled;
moveAction.Enable();
#

Similarly, in the "OnDisable()" method, disable the input action and unsubscribe from the events:

#
moveAction.canceled -= OnMoveCanceled;
moveAction.Disable();
#

Add the event handlers for the move action:

#
{
    m_characterMovement = context.ReadValue<Vector2>();
}

private void OnMoveCanceled(InputAction.CallbackContext context)
{
    m_characterMovement = Vector2.zero;
}
#

Finally, modify the "Update()" method to move the player character using the character movement input:

#
{
    ICharacter player = PowerQuest.Get.GetPlayer();
    Vector2 newPosition = player.Position + m_characterMovement * player.WalkSpeed * Time.deltaTime;
    player.SetPosition(newPosition);
}