New Input System - 2D Move
I keep looking up how to move the character using the new input system for 2D using "Invoke Unity Events." This is what my successful setup looks like.
Last updated
I keep looking up how to move the character using the new input system for 2D using "Invoke Unity Events." This is what my successful setup looks like.
Last updated
Right click in the project folder and then go to "Create" -> Input Actions
This has four components. I've opted to put the sprite rendered on a child game object of this because of a shielding function later.
The components needed here are:
Collider2D - Anyone will do
Rigidbody 2D
Player Input
Custom script to control the player gameobject, named here "Player Controller"
Note: For the "Collision Detection" property, set it to "Continuous" or the camera gets shaky.
Because we're going to be "Behavior: Invoke Unity Events," you do not need the following code.
This method is more performant than "Broadcast Messages" because this will only trigger once the input is interacted with rather than sending it every frame.
PlayerController.cs script that is attached to the player GameObject in the scene.
Be sure to add "using UnityEngine.InputSystem;" The parameter "InputAction.CallbackContext ctx" makes this device specific. If you don't include it, it will read all the input from all devices for one character. "ctx" can be called anything but "InputAction.CallbackContext" has to remain the same.
Alternate way to move character.