![]() ![]() And I’m gonna drag this script into the Inspector to attach it as a component. I’m gonna right click create a new C# script called Camera Follow. Down here on my scripts folder, inside with project browser. So, what we need to do is create a new script. And if we move it above player, you’ll see there’s this blue line that appears. So to unparent an objects, we can select it, click and drag. We don’t want to pretty much be statically attached to our player like this, where you rotate and move with it. And you’ll see that when we move, our camera rotates as well with our player. Okay, so the camera is now a child, and if we press play, we should be able to move our player around, right? So I’m gonna get our camera and I’m gonna drag that into the player object as a child. Okay well, let’s try that out and see if it works. So that whenever it moves, the camera moves as well. Now, first of all, you may think we can just parent the camera to the player. So here in Unity, what we want to do first of all, is figure out how we’re actually going to do this. And this basically means that we have our camera following our player around, so no matter where we go, we can always have our player in the center of our screen. Welcome back everyone in this lesson, we are going to be setting up Camera Follow. If we hit Play now, you should see that the camera is following our player, while always maintaining the offset (0, 2, -3.5) away from the player’s position. We’re also going to set the x-rotation of our camera to be 20, so we’re looking down slightly on the player. We’re going to set the offset as (0, 2, -3.5): Now we’re going to drag in the Player into the Target slot. Transform.position = target.position + offset Inside the Update function, we’re going to update our camera’s position so that it follows the target’s position, but with some offset so that our camera doesn’t sit inside the player. The target will be used to reference a Transform component to follow, and the offset will be used to maintain a certain distance away from the player. Here, we’re going to create two new variables: public Transform target We can then double-click the script and open it up in Visual Studio. We’re going to attach this script to the camera by dragging it into the Inspector. (Drop it into where the blue line appears above the Player):Īnd we’re going to create a new script called “CameraFollow” inside Assets/Scripts. Creating A CameraFollow Scriptįirst, we’re going to unparent the camera from the Player. However, the camera not only follows our Player’s position, but it also follows its rotation.įor example, if you are facing right and hit the left key, the camera is also turned 180 degrees, and this is not ideal. If we press play, we can see the camera follows our Player. Now the camera is set as a child of the Player. You can click on the camera and drag it into the Player object: Jumping.extraHeight = jumping.The simplest way to make a camera follow an object is to set it as a child. Change extraheight value to default when player walk Movement.maxBackwardsSpeed = movement.WalkSpeed/2 Movement.maxSidewaysSpeed = movement.WalkSpeed Movement.maxForwardSpeed = movement.WalkSpeed Jumping.extraHeight = jumping.baseHeight + 0.15f Make bigger extra height when player run to increase jump distance Movement.maxSidewaysSpeed = movement.RunSpeed Movement.maxForwardSpeed = movement.RunSpeed GetComponent ().RPC ("SysnAnimation", RPCMode.All, 2) GetComponent ().RPC ("SysnAnimation", RPCMode.All, 1) public class FPScontroller : MonoBehaviour else if ( ().RPC ("SysnAnimation", RPCMode.All, 0) When my camera rotate Left side to then player rotate to the left side but when i press my joystick button forward then player can't move forward can't change the moving direction of Player. My Problem is when the camera facing is change my player movement is not follow the camera facing. Player can touch the screen and rotate the camera using swipe. ![]() I have my Player Camera that rotate Around the Player. ![]()
0 Comments
Leave a Reply. |