Raycasting with the Unity’s New Input System

Поділитися
Вставка
  • Опубліковано 11 лип 2024
  • Raycasting with Unity's New Input System. FPS Shooting, selecting objects, moving objects, jumping (checking if touching the ground). Converting from old to new input system.
    First Raycasting Video: • Unity Raycasting - 4 E...
    New Input System Video: • Unity's "NEW" Input Sy...
    More Info On Started, Performed, and Canceled Events: forum.unity.com/threads/learn...
    Want to support the Channel?
    *******************************
    Shop the Unity Asset Store (affiliate): assetstore.unity.com/top-asse...
    Become A Channel Member: / @onewheelstudio
    Or a Patron: / onewheelstudio
    Grab a T-Shirt: onewheelstudio.com/merch/
    My video and streaming kit: kit.co/onewheelstudio/tutoria...
    Buy a Game Design Book: kit.co/onewheelstudio/game-de...
    Other Links
    ************
    Discord: discord.onewheelstudio.com
    Twitter: / onewheelstudio
    Devlog: onewheelstudio.com/
    Twitch: / onewheelstudio
    Video Gear List (Amazon Affiliate)
    ************
    Sony A6100 Camera: amzn.to/32logXz
    Sigma 16mm 1.4 Camera Lens: amzn.to/3KA4Wr4
    GoXLR (audio interface): amzn.to/35dmr03
    Shure SM7B Mic: amzn.to/3fNbV1E
    Blue Mic Arm: amzn.to/3tHgwdQ
    Neewer Light: amzn.to/3rD8eRv
    Light Softbox: amzn.to/3GUaHgQ
    Neewer RGB Light: amzn.to/3rCTQJ9
    Timestamps
    *************
    0:00 Intro
    0:45 First Person Shooting
    2:21 Performed Event
    4:30 Selecting Objects
    6:04 Started and Canceled Events
    9:16 Selecting and Moving Objects
    10:36 Polling of Mouse Buttons
    12:15 Jumping (Is Grounded)
    12:47 Polling of Keyboard
    #GameDevelopment #Unity3D #NewInputSystem
  • Наука та технологія

КОМЕНТАРІ • 28

  • @Fuzzel
    @Fuzzel 2 роки тому +14

    You missed a thing when converting your old second and third example to the new input system: You continue to use Input.mousePosition which is part of the old input system and only works because in your project you still have both the new and old input system enabled. The new way is Mouse.current.position.ReadValue() or using the control mapping asset and creating a Vector2 binding for /position which you can then also read out inside an update using ReadValue().
    Also instead of using isPressed you can also use wasPressedThisFrame and wasReleasedThisFrame for the start and end of the pickup

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      You are totally right! Big brain fart! Thanks.
      Also, I looked for something like isPressedThisFrame and missed it. Much appreciated.

    • @ap0stle
      @ap0stle Рік тому

      I am currently trying to raycast using the new input system using input action to receive mouse position, but it returns the mouse position on global screen, when old input system mouse position returns the mouse position in the game window. I've been suffering a lot before I realized that my raycasts don't work because the mouse position from the new input system just is incorrect
      As you mentioned it, maybe you know how I can fix it?

  • @umapessoa6051
    @umapessoa6051 2 роки тому +1

    Awesome as always, keep up with the great work.

  • @jakovincenttumane225
    @jakovincenttumane225 2 роки тому

    4 min into the video and now my input system works perfect thanks bro

  • @thesilentwisp
    @thesilentwisp 2 роки тому

    Really well explained thank you. Not sure if you can address this but I had a hard time giving the player a way to change mouse sensitivity with the new input system using the cinemachine camera.

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому +1

      Thanks! Glad it was useful.
      As for the mouse you could multiply the input by a float. Make it less than one to slow the mouse. More than one to speed it up. I haven’t done it but that would be my first attempt.

    • @thesilentwisp
      @thesilentwisp 2 роки тому

      @@OneWheelStudio I've looked and could not for the life of me figure it out. If you happen to be unsure of what to make for your next video, that might be an idea since literally no one on UA-cam covers reading mouse vector 2 input with the new input system in a cinemachine freelook camera.

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      The free-look camera? That is a bit tougher but not much. You can open up the "Cinemachine Input Provider" script and add the value that I was describing above.
      I'm going to be away all day today, but you're welcome to jump on the OWS discord and I bet we can get something working.
      You may be right that this could be a good quick follow-up video.

  • @RobLang
    @RobLang 2 роки тому

    This is a great run through, thank you. One small thing - I found that your face cam had trouble focusing on your face when gesticulating. For me, a locked focus would be great!

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      Yep I’m with you. I’ve been struggling with the focus and learning a bunch in the process. Still a bit scared of locking the focus but I’ve changed some other settings which will hopefully let it stick to my face better. We’ll see.
      Glad the video is helpful!

  • @orchard800
    @orchard800 2 роки тому +1

    Brilliant video. Just one question though; why enable sa.player in onenable()? And why enable it after subscribing to it, not before? If it wasn't enabled, would you be able to subscribe to it?

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      The order of enabling and subscribing doesn't matter - I don't know the exact inner workings of the Input Action Asset, but calling Enable doesn't turn the object on or off, it just tells it to listen to inputs and send out corresponding events.
      As for why we subscribe in OnEnable (and unsubscribe in OnDisable), this ensures that the functions are subscribed even if the object is turned on/off.

  • @lee1davis1
    @lee1davis1 2 роки тому

    Well you be doing a video on custom key binding manager with the new input system?

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      Done! ;)
      See if this video gets you moving in the right direction: ua-cam.com/video/TD0R5x0yL0Y/v-deo.html

  • @monkeymonkey69696
    @monkeymonkey69696 3 місяці тому

    Thanks

  • @JacksonThom
    @JacksonThom Рік тому

    This is a great tutorial, but what is it about Cinemachine that can be set, to get it to follow the mouse pointer? I have been struggling with this for, soooo long! Thanks!

    • @OneWheelStudio
      @OneWheelStudio  Рік тому

      I'm not sure I would use Cinemachine for that. What you could do is raycast from the camera through the mouse and get a point on the ground. You could then have the camera "LookAt" the point on the ground. Do a quick google search for "unity raycast camera to mouse" and you should find plenty of results. Then look up "unity transform lookat"

  • @Seiku
    @Seiku 2 роки тому

    Just a curious question, I'm still trying to grasp scripting and whatnot. I was learning and trying to implement a custom 2D collision script with raycasts and/or boxcasts on a sprite to detect ground collisions etc. Is this something that could be used for that, for a custom player collision, instead of updating every frame with the raycast?

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      Yep. Raycasting is a great way to detect ground collisions. Sebastian Lague has a great (but not simple) series on creating a 2D platformer using ray casting. Playlist: ua-cam.com/play/PLFt_AvWsXl0f0hqURlhyIoAabKPgRsqjz.html

  • @leyone6828
    @leyone6828 2 роки тому

    Hi, I am wondering if you have a tutorial of the project you demonstrated at 0:09, how objects are generated following the cursor but restricted in a certain grid (not sure if I say it correctly)

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      I don't have a video on that in particular, but the basic idea is to get the location (via raycast) which returns a Vector3. You can then round each of the components to an integer. Once they are rounded you can create a new vector3 with the rounded values and use THAT for the positioning.

    • @leyone6828
      @leyone6828 2 роки тому +1

      @@OneWheelStudio Thank you so much for the detailed explanation!

  • @hansa5867
    @hansa5867 Рік тому

    The videos recommended in the beginning lack video links, I think, I didn't have them at least. So if you want to implement those, do so :)

    • @OneWheelStudio
      @OneWheelStudio  Рік тому

      There are links to the videos mentioned at 0:24 in the description as well as cards in the top right of the video. Happy to add others if I missed on.

  • @harryrithman1977
    @harryrithman1977 2 роки тому

    Apparently unity does not come with input system I had get off asset store which one do you have

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      Yes, Unity still defaults to the "old" input system and the "new" system has to be imported with the package manager.
      This video used version 1.0.2 with Unity 2019.4.

    • @harryrithman1977
      @harryrithman1977 2 роки тому

      @@OneWheelStudio no I mean when I downloaded unity there was no input system in package manager I had get one from asset store