icon Tekstitykset
Ladataan tekstityksiä...

Build Better Camera Controls in Unity

youtube käännös youtube kääntäjä youtube transkriptio youtube tekstitys kääntää youtube suomeksi youtube videon käännös youtube translate to finnish translate youtube to finnish youtube transcript to finnish translate youtube video to finnish

YouTube transcript, YouTube translate

32/32

A quick preview of the first subtitles so you know what the video covers.

One of the most important parts of any game is the camera controls. The player will be moving the camera almost the entire game, so it's essential that the camera feels good. So, in this video, I want to show you how to write a robust, smooth camera control script that works for both mouse and gamepad stick input. I won't be covering character movement in this video. For that, I'm using Traversal Pro. That's a character controller asset I created. You can check it out on the Unity asset store if you're interested. All right, let's get started. First, let's create a new script called view control. We need a vector 2 field named degrees to store the rotation of the camera. We're going to use the input system to read player input. So, let's write a public method called input. It needs a parameter of type input action.allback context. We need to separate mouse input from stick input because they mean different things. Mouse input represents an absolute offset, a one-time movement where you're saying you want the camera to move with the mouse, then stop moving when the mouse stops. But stick input represents a velocity. So when I move the stick to the right and leave it there, I want the camera to keep spinning to the right until I let go of the stick. This all means we need to record mouse and stick input separately. So let's write two more vector 2 fields and name them mouse input and stick input. I used to actually create two separate input methods, one for mouse and one for stick. But I discovered there's an easy way to get them both in this one method. In the input system, controls that represent onetime offsets like mouse input are all named delta. So we can just check if that's the controls name, and if so, record it as mouse input. Otherwise, we record it as stick input. And that's it for reading the input. Now, we need to use the input. So let's add an update method. We need to add the input to the degrees field, but we need to swap the values around and negate the y input. But why on earth would we need to do that?

Asetukset

100%

Käännöksen kohdekieli

🔊 Äänien toisto
Käännetyn äänen toisto