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 - Наука та технологія
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
You are totally right! Big brain fart! Thanks.
Also, I looked for something like isPressedThisFrame and missed it. Much appreciated.
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?
Awesome as always, keep up with the great work.
4 min into the video and now my input system works perfect thanks bro
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.
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.
@@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.
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.
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!
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!
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?
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.
Well you be doing a video on custom key binding manager with the new input system?
Done! ;)
See if this video gets you moving in the right direction: ua-cam.com/video/TD0R5x0yL0Y/v-deo.html
Thanks
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!
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"
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?
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
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)
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.
@@OneWheelStudio Thank you so much for the detailed explanation!
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 :)
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.
Apparently unity does not come with input system I had get off asset store which one do you have
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.
@@OneWheelStudio no I mean when I downloaded unity there was no input system in package manager I had get one from asset store