

You should use Vector3.Slerp (spherical interpolation) instead. On the Vector Lerp, note that this will not give a unit vector. Over time and through experiments with trying out different control schemes, game designers have figured out that players find the controls more intuitive and easier to understand when “left” means “left-hand side of the screen” (which, not coincidentally, is also the player’s left). Yeah I kept wondering why I saw rather strange t values in Lerp examples from Unity and in others code. The parameter u moves from 0 (where the expression simplifies to q 1) to 1 (where the expression simplifies to q 2 ).

It is defined as: Slerp ( q 1, q 2 u) q 1 ( q 1 1 q 2) u. geodesic) on the unit hypersphere between two quaternions q 1 and q 2. Here’s where X and Z values are set in the movement vector, for horizontal movement around the scene. It describes an interpolation (with constant angular velocity) along the shortest path (a.k.a.

Next, check the input controls, just as you have in previous scripts. When the player presses the left button, the character moves to the left of the screen, not the character’s left. The remaining code will replace this vector if the player is pressing any buttons, but it’s important to have a default value in case there isn’t any input. As such, you have to decide what you want to have happen in your specific game and controls setup.Īlthough games occasionally do it the other way, most third-person games make their controls camera-relative. For example, they’re literally opposite directions if the camera is looking at the front of the character. w represents the degree of rotation along the unit vector. A third-person view places the camera outside the character, though, and thus the camera’s left may be pointed in a different direction from the character’s left. If you want to rotate the object to a specific angle use: float degrees 90 Vector3 to new Vector3 (degrees, 0, 0) transform. Lets try to rotate a cube from the initial position to a certain angle. The camera in a first-person game is placed inside the character and moves with it, so no distinction exists between the character’s left and the camera’s left. This is similar to the local versus global distinction mentioned in previous chapters: “left” points in different directions when you mean “left of the local object” or “left of the entire world.” In a similar way, when you “move the character to the left,” do you mean toward the character’s left, or the left-hand side of the screen? At least, its what the documentation says, or Im interpreting wrong. The whole notion of “camera-relative” is a bit nonobvious but very crucial to understand. I think slerp needs two vectors to be able to run.
