Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Reading mouse input on button down and on release with new input system

Discussion in 'Input System' started by unity_8dcMkJ6cI2bL3w, Oct 20, 2022.

  1. unity_8dcMkJ6cI2bL3w

    unity_8dcMkJ6cI2bL3w

    Joined:
    May 19, 2022
    Posts:
    2
    Hi,

    So I want to create a fighting system similar to Skyrim or KCD. There's a great tutorial here:


    The problem is that it uses the old input system. Now I imagine the code is similar and would be a simple matter of giving each action a screen space Vector2 position so it knows which action/method to execute, just like in the video. The issue I'm having is translating that to the input action controller. I assume I could name an action 'Thrust' for example and have it read LeftMouse tap and the mouse delta, then define the screen space coordinates in code, as shown in the video?

    If I were to take it a step further, since I want to test another combat system to see which flows best, what if I wanted to read screen space mouse location on left mouse down and read again on left mouse release and then compare the two values? In code I assume this would be a simple matter of storing the Vector2 on mouse down, storing the Vector2 on release and checking if the Y on release is less than the Y on down and if so execute the 'Thrust' action. But in the input controller I didnt see anything about tracking Vector2 values on mouse down and I didn't see anything about tracking mouse release.

    If this is semi understandable and someone could explain, it'd be much appreciated. Or if someone could point me in the right direction so I could do more research. Thanks!
     
  2. sunsi12138

    sunsi12138

    Joined:
    Apr 14, 2020
    Posts:
    23
    use Mouse.current.position.ReadValue() to get mouse position,

    you can call this and record the position by subscribe to mouse left button event "start" and "cancel" with PlayerInput or
    InputActionReference
     
  3. unity_8dcMkJ6cI2bL3w

    unity_8dcMkJ6cI2bL3w

    Joined:
    May 19, 2022
    Posts:
    2
    Gotcha. So I'm assuming that 'start' would record on press and 'cancel' would record on release? I'm also guessing that in the input action map, I'd just create actions associated with each attack (thrust, left swing, right swing, overhead swing, etc...) and assign each of them to left mouse button. Then in the PlayerInput script I'd use Mouse.current.position.ReadValue() and compare that screen space Vector2 I have assigned for each attack?

    For the press and release style combat, if I want to go that way, I'd do the same but subtract the on press Vector2 to the on release Vector2 and compare that variable to the value I have laid out for each attack?

    Also, thanks for the reply, I appreciate the help.