banner



How To Rotate A Camera In Unity


In this tutorial, we will implement a configurable third-person camera control in Unity for an animated character. Our target game object for this tutorial volition be a proper animated game object rather than a cylinder or a capsule.

Expect at the video beneath on what we volition achieve by the end of our tutorial.

This tutorial is divided into three sections.

  1. In Section 1. nosotros will concentrate on setting up the scene and the animated character.
  2. In Section two, we will implement the necessary third-person camera controls for PC, Linux and Mac build settings.
  3. In Section 3 we will port the third-person camera controls for affect screen devices with a virtual joystick and deploy to an Android phone.

Read besides: Implementing Player Controls With Finite State Machine Using C# in Unity


Department ane – Scene and Character Setup

Create a Unity 3D project

Create a Elementary Scene

Download the following complimentary Avails from the Unity Nugget Shop

Sci Fi Warrior PBR HP Polyart

Import these assets. Nosotros will use this as our role player and center our third-person camera command around this player.

The imported assets comprise three prefabs and 1 blitheness controller. We will apply one of these prefabs and create a new animation controller that volition adapt our needs.

Create the Character'south Animation Controller

Create a new binder called Resources in Assets and create another binder chosen Animations inside the Resources folder.

Right-click on the Project window → Create Animation Controller.

Name information technology PlayerAnim.

We will use Blend Tree to create movement control for the histrion. To know more almost Unity Alloy Tree refer to Unity documentation.

Right-click anywhere in the Base of operations Layer window of the PlayerAnim blitheness controller and click on Create State From New Blend Tree

Double click and select the newly created Blend Tree.

Rename information technology to Basis Movement or any other name that you fancy. Select Basis Motion and modify the Blend Type to 2D Freeform Directional.

Now add 2 new bladder parameters chosen PosX and PosZ. These are the parameters that nosotros volition use to dispense the animations of the thespian based on inputs.

We will now showtime adding animations to the Footing Move Blend Tree. Nosotros will practise this past clicking on the + sign in Motions field.

Click on the + and select Add together Motion Field.

Create the Player

We will at present create the actual player. For this, nosotros create an empty game object and rename information technology to Player. Drag and drop the HPCharacter prefab to the Player game object. Change the Animation Controller to the newly created PlayerAnim.

Add together the Grapheme Controller component to Player. Alter the Heart Y value to ane.1.

For ameliorate view add the below paradigm as a texture to the basis.

Go to Window → Rendering → Lighting Settings and open up the Lighting window. Now check the Baked Global Illumination and click Generate Lighting.

Create a Player motion script

We volition now create a movement controller for the character. This will allow us to control the movement of the graphic symbol by using keyboard and mouse inputs for PCs and a virtual joystick for touch screen devices. For now, nosotros will only concentrate on build for PC, Linux and Mac. We will handle touch screen devices in the later on office of the tutorial.

Create a new script file called PlayerMovement.cs and adhere the script to the Histrion game object. Call back that Role player is an empty game object that holds the actual character with the AnimationController.

Add together the post-obit content into PlayerMovement.cs

          

using System.Collections; using Arrangement.Collections.Generic; using UnityEngine; [RequireComponent(typeof(CharacterController))] public course PlayerMovement : MonoBehaviour { [HideInInspector] public CharacterController mCharacterController; public Animator mAnimator; public bladder mWalkSpeed = 1.5f; public bladder mRunSpeed = 3.0f; public float mRotationSpeed = 50.0f; public float mGravity = -30.0f; private Vector3 mVelocity = new Vector3(0.0f, 0.0f, 0.0f); // Outset is called earlier the get-go frame update void Start() { mCharacterController = GetComponent<CharacterController>(); } void Update() { Move(); } public void Motion() { float h = Input.GetAxis("Horizontal"); float five = Input.GetAxis("Vertical"); float speed = mWalkSpeed; if (Input.GetKey(KeyCode.LeftShift)) { speed = mRunSpeed; } mCharacterController.Move(transform.frontwards * 5 * speed * Time.deltaTime); transform.Rotate(0.0f, h * mRotationSpeed * Fourth dimension.deltaTime, 0.0f); if (mAnimator != goose egg) { mAnimator.SetFloat("PosZ", v * speed / mRunSpeed); } // apply gravity. mVelocity.y += mGravity * Time.deltaTime; mCharacterController.Motility(mVelocity * Time.deltaTime); if (mCharacterController.isGrounded && mVelocity.y < 0) mVelocity.y = 0f; } }

Lawmaking linguistic communication: C# ( cs )

Set the Animator value by dragging and dropping the HPCharacter into the M Animator field of the PlayerMovement.

Click Play and test the application.

We will come back to PlayerMovement afterward again to enhance its functionality. We motility on to implement the third-person camera command at present one step at a time. By the time we end, we promise to create a robust third-person camera control organisation.


Section ii – Implement Third-person Photographic camera Controls

In this tutorial we volition implement a broad variety of third-person camera controls and depending on your need you tin apply i of these camera command types. Nosotros volition also make the control parameters variable so that they can be configured. Permit's go on.

Create a new script chosen ThirdPersonCamera.cs and add it as component of the Chief Camera.

ane. Rail – third-person camera control

In this mode nosotros volition permit the camera runway a game object by setting the LookAt value to be the designated game object'due south position. In this mode the camera does non modify it position. This is by far the simplest third-person photographic camera command.

Double click on ThirdPersonCamera.cs and open the file in your favourite IDE.

We will implement our third-person camera functionality in LateUpdate.

From Unity: LateUpdate is called every frame if the Behaviour is enabled. LateUpdate is chosen afterward all Update functions have been called. This is useful to order script execution. For example, a follow camera should always be implemented in LateUpdate because information technology tracks objects that might have moved inside Update.

          

using System.Collections; using Arrangement.Collections.Generic; using UnityEngine; public class ThirdPersonCamera : MonoBehaviour { public enum ThirdPersonCameraType { Track, } public ThirdPersonCameraType mThirdPersonCameraType = ThirdPersonCameraType.Track; public Transform mPlayer; void Commencement() { } void Update() { } void LateUpdate() { switch (mThirdPersonCameraType) { case ThirdPersonCameraType.Runway: { CameraMove_Track(); break; } } } void CameraMove_Track() { transform.LookAt(mPlayer.transform.position); } }

Lawmaking language: C# ( cs )

Yous can see that we have created an enum blazon called ThirdPersonCameraType. This is because nosotros intend to implement more than one type of third-party camera control.

Click play and view the behavior.

https://faramira.com/wp-content/uploads/2020/06/Track_ThirdPersonCamera.mp4
1. Track – third-person camera control

For our animated grapheme, the position of the transform is at top 0. If you desire to track the target'southward total superlative and so we volition need to add together the actor'due south height into the LookAt position.

So, we alter the CameraMove_Track function to the cater for the actor'due south height. For this we will need to add another public variable called mPlayerHeight.

          

// add together a new variable to allow setting of the player'south summit. public float mPlayerHeight = two.0f; ***** void CameraMove_Track() { Vector3 targetPos = mPlayer.transform.position; targetPos.y += mPlayerHeight; transform.LookAt(targetPos); }

Lawmaking language: C# ( cs )

Now, click play and see the behaviour.

https://faramira.com/wp-content/uploads/2020/06/ThirdPersonShooterCamera-SampleScene-PC-Mac-Linux-Standalone-Unity-2019.3.8f1-Personal-_DX11_-2020-06-26-22-32-09.mp4
1. Track – third-person photographic camera control with Player height.

You tin run into the difference betwixt the two implementations. You tin alter the height of the player depending on your where you would want the camera to look at.


two. Follow – third-person camera control

Our next implementation of a third-person camera command volition be called Follow where the camera follows the target player. The player moves and the camera follows. However, the rotation of the player does non affect the camera.

For this we will introduce three new variables. These are:

  • The initial position offset of the camera. This will determine where the camera is with respect to the thespian.
  • The initial rotation offset of the photographic camera
  • The damping factor to smoothen the changes to the position and rotation of the camera.
          

using Organisation.Collections; using System.Collections.Generic; using UnityEngine; public form ThirdPersonCamera : MonoBehaviour { public enum ThirdPersonCameraType { Track, Follow, } public ThirdPersonCameraType mThirdPersonCameraType = ThirdPersonCameraType.Track; public Transform mPlayer; public float mPlayerHeight = 2.0f; public Vector3 mPositionOffset = new Vector3(0.0f, 2.0f, -two.5f); public Vector3 mAngleOffset = new Vector3(0.0f, 0.0f, 0.0f); [Tooltip("The damping factor to smooth the changes " + "in position and rotation of the photographic camera.")] public bladder mDamping = one.0f; void Beginning() { } void Update() { } void LateUpdate() { switch (mThirdPersonCameraType) { case ThirdPersonCameraType.Rails: { CameraMove_Track(); break; } case ThirdPersonCameraType.Follow: { CameraMove_Follow(); pause; } } } void CameraMove_Track() { Vector3 targetPos = mPlayer.transform.position; targetPos.y += mPlayerHeight; transform.LookAt(targetPos); } // Follow photographic camera implementation. void CameraMove_Follow() { // We apply the initial rotation to the camera. Quaternion initialRotation = Quaternion.Euler(mAngleOffset); transform.rotation = Quaternion.RotateTowards( transform.rotation, initialRotation, mDamping * Time.deltaTime); // Now we summate the camera transformed axes. Vector3 forward = transform.rotation * Vector3.forward; Vector3 right = transform.rotation * Vector3.right; Vector3 upwards = transform.rotation * Vector3.up; // We so summate the kickoff in the // camera'southward coordinate frame. Vector3 targetPos = mPlayer.position; Vector3 desiredPosition = targetPos + forward * mPositionOffset.z + right * mPositionOffset.x + up * mPositionOffset.y; // Finally, nosotros change the position of the camera, // non directly, but by applying Lerp. Vector3 position = Vector3.Lerp( transform.position, desiredPosition, Time.deltaTime * mDamping); transform.position = position; } }

Code language: C# ( cs )

We also see that the mPlayerHeight is redundant now as we tin can use the mPositionOffset.y equally the acme of the player for our CameraMove_Track implementation.

          

***** void CameraMove_Track() { Vector3 targetPos = mPlayer.transform.position; // We removed mPlayerHeight and replaced // with the mPositionOffset.y targetPos.y += mPositionOffset.y; transform.LookAt(targetPos); } *****

Code linguistic communication: C# ( cs )

Click Play and view the behaviour.

https://faramira.com/wp-content/uploads/2020/06/ThirdPersonShooterCamera-SampleScene-PC-Mac-Linux-Standalone-Unity-2019.3.8f1-Personal_-_DX11_-2020-06-27-00-13-25.mp4
2. Follow – 3rd-person camera control

You lot tin can run across that by toggling from Track to Follow how the camera behaves. You can also change the various parameters to see how it affects the camera view.


3. Follow and Track Rotation – third-person camera command

This is an extension of the Follow third-person camera command where the camera follows and rotates based on the player'due south rotation. This mode basically keeps rails of the player's position as well equally the rotation.

To implement this nosotros add a new type in enum ThirdPersonCameraType called Follow_TrackRotation. Later on that, we refactor the CameraMove_Follow role with an input bool parameter called allowRotationTracking. Nosotros and then meliorate the office to handle the player's rotation.

          

// Follow camera implementation. // Refactored to allow but positional tracking or // positional tracking and rotational tracking. For this nosotros // added a bool parameter called allowRotationTracking. void CameraMove_Follow( bool allowRotationTracking = simulated ) { // Nosotros apply the initial rotation to the photographic camera. Quaternion initialRotation = Quaternion.Euler(mAngleOffset); // added the post-obit code to allow rotation // tracking of the player // so that our camera rotates when the player // rotates and at the aforementioned // time maintain the initial rotation showtime. if (allowRotationTracking) { Quaternion rot = Quaternion.Lerp( transform.rotation, mPlayer.rotation * initialRotation, Time.deltaTime * mDamping); transform.rotation = rot; } else { transform.rotation = Quaternion.RotateTowards( transform.rotation, initialRotation, mDamping * Time.deltaTime); } // Now we calculate the camera transformed axes. Vector3 frontwards = transform.rotation * Vector3.forward; Vector3 right = transform.rotation * Vector3.right; Vector3 upward = transform.rotation * Vector3.up; // We then calculate the first in the // camera's coordinate frame. Vector3 targetPos = mPlayer.position; Vector3 desiredPosition = targetPos + forwards * mPositionOffset.z + right * mPositionOffset.x + up * mPositionOffset.y; // Finally, nosotros change the position of the camera, // not directly, but past applying Lerp. Vector3 position = Vector3.Lerp(transform.position, desiredPosition, Time.deltaTime * mDamping); transform.position = position; }

Code language: C# ( cs )

Click Play and observe the behaviour.

https://faramira.com/wp-content/uploads/2020/06/Follow_TrackRotation_ThirdPersonCamera.mp4
3. Follow and Track Rotation – third-person camera command

4. Follow and Independent Rotation – third-person camera control

In this way of third-person camera the camera follows the target player but the camera has independent rotation based on mouse input. This style of camera is generally used in touch on screen devices where the virtual joystick controls the player's motion where as the impact and drag on the screen handles the rotation.

Many times instead of applying the rotation to the player directly the rotation is practical on to the camera. So whenever the role player moves information technology orients itself to the camera'due south forwards direction. It allows independent rotation of the camera when the player is stationary.

For this mode we add a new enum value called the Follow_IndependentRotation. We then implement the function named Follow_IndependentRotation.

To implement this mode of camera behaviour we also introduce 3 new public variables and 1 private variable.

          

void Follow_IndependentRotation() { float mx, my; mx = Input.GetAxis("Mouse X"); my = Input.GetAxis("Mouse Y"); // Nosotros employ the initial rotation to the camera. Quaternion initialRotation = Quaternion.Euler(mAngleOffset); Vector3 eu = transform.rotation.eulerAngles; angleX -= my * mRotationSpeed; // We clench the bending along the X axis to be between // the min and max pitch. angleX = Mathf.Clench(angleX, mMinPitch, mMaxPitch); eu.y += mx * mRotationSpeed; Quaternion newRot = Quaternion.Euler(angleX, eu.y, 0.0f) * initialRotation; transform.rotation = newRot; Vector3 forward = transform.rotation * Vector3.forward; Vector3 right = transform.rotation * Vector3.correct; Vector3 up = transform.rotation * Vector3.up; Vector3 targetPos = mPlayer.position; Vector3 desiredPosition = targetPos + forwards * mPositionOffset.z + correct * mPositionOffset.x + upward * mPositionOffset.y; Vector3 position = Vector3.Lerp(transform.position, desiredPosition, Time.deltaTime * mDamping); transform.position = position; }

Code linguistic communication: C# ( cs )

Click play and select Follow_IndependentRotation mode from the dropdown. See the behaviour.

https://faramira.com/wp-content/uploads/2020/06/Follow_IndependentRotation_ThirdPersonCamera.mp4
four. Follow and Contained Rotation – third-person camera control

All the same, yous might have noticed that this camera is not very useful unless y'all make the player follow the camera's rotation. We now open up our PlayerMovement.cs script and modify to permit the player to rotate based on the camera's forward direction.

We add a new boolean variable called mFollowCameraForward. This flag will decide if the player should align to the camera's forrard direction. We besides add a new bladder variable called mTurnRate that will determine the charge per unit at which the player will turn to alight itself with the camera'south forward direction. It is same every bit the damping factor but with a different name.

          

public void Motility() { bladder h = Input.GetAxis("Horizontal"); float 5 = Input.GetAxis("Vertical"); float speed = mWalkSpeed; if (Input.GetKey(KeyCode.LeftShift)) { speed = mRunSpeed; } if (mFollowCameraForward) { // Merely allow aligning of role player's management when // at that place is a move. if (v > 0.1 || five < -0.1 || h > 0.1 || h < -0.1) { // rotate player towards the camera forward. Vector3 eu = Photographic camera.main.transform.rotation.eulerAngles; transform.rotation = Quaternion.RotateTowards( transform.rotation, Quaternion.Euler(0.0f, eu.y, 0.0f), mTurnRate * Time.deltaTime); } } else { transform.Rotate(0.0f, h * mRotationSpeed * Fourth dimension.deltaTime, 0.0f); } //transform.Rotate(0.0f, h * mRotationSpeed * Fourth dimension.deltaTime, 0.0f); mCharacterController.Move(transform.forward * five * speed * Time.deltaTime); if (mAnimator != zip) { mAnimator.SetFloat("PosZ", 5 * speed / mRunSpeed); } // apply gravity. mVelocity.y += mGravity * Time.deltaTime; mCharacterController.Move(mVelocity * Fourth dimension.deltaTime); if (mCharacterController.isGrounded && mVelocity.y < 0) mVelocity.y = 0f; }

Code language: C# ( cs )

See the amended code in the highlighted lines.

Click Play now and see the camera equally well every bit the Histrion behaviour.

https://faramira.com/wp-content/uploads/2020/06/ThirdPersonShooterCamera-SampleScene-PC-Mac-Linux-Standalone-Unity-2019.3.8f1-Personal_-_DX11_-2020-06-27-01-sixteen-43.mp4
4. Follow and Independent Rotation – tertiary-person camera control while player tracking camera's frontward management.

5. Top-Downward – 3rd-person camera command

The final manner is a uncomplicated Top-Down camera way where the camera looks down on the actor from an distance. This manner will not use the mRotationOffset and the 10 and z values of the mPositionOffset.

The implementation is simple as shown below.

          

void CameraMove_TopDown() { // For topdown camera we do not apply the x and z offsets. Vector3 targetPos = mPlayer.position; targetPos.y += mPositionOffset.y; Vector3 position = Vector3.Lerp( transform.position, targetPos, Time.deltaTime * mDamping); transform.position = position; transform.rotation = Quaternion.Euler(ninety.0f, 0.0f, 0.0f); }

Code language: C# ( cs )

Click Play, select the TopDown mode and view the behaviour. Remember to disable the M Follow Photographic camera Forwards boolean field for the PlayerMovement.

https://faramira.com/wp-content/uploads/2020/06/ThirdPersonShooterCamera-SampleScene-PC-Mac-Linux-Standalone-Unity-2019.3.8f1-Personal-_DX11_-2020-06-27-01-28-13.mp4
v. Top-Downwardly – third-person camera control

This concludes the tutorial on how to create a custom third-person camera control in Unity. This tutorial provides nigh all possible implementations of a possible third-person camera control. If y'all take any doubts or any questions please feel complimentary to write in the comments department.

The Final Scripts

PlayerMovement.cs

          

using System.Collections; using Organization.Collections.Generic; using UnityEngine; [RequireComponent(typeof(CharacterController))] public class PlayerMovement : MonoBehaviour { [HideInInspector] public CharacterController mCharacterController; public Animator mAnimator; public float mWalkSpeed = 1.5f; public bladder mRunSpeed = 3.0f; public float mRotationSpeed = 50.0f; public float mGravity = -30.0f; [Tooltip("Only useful with Follow and Independent " + "Rotation - third - person camera control")] public bool mFollowCameraForward = simulated; public float mTurnRate = 200.0f; private Vector3 mVelocity = new Vector3(0.0f, 0.0f, 0.0f); // First is called before the first frame update void Start() { mCharacterController = GetComponent<CharacterController>(); } void Update() { Movement(); } public void Move() { bladder h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); bladder speed = mWalkSpeed; if (Input.GetKey(KeyCode.LeftShift)) { speed = mRunSpeed; } if (mFollowCameraForward) { // Merely allow aligning of actor'due south direction // when there is a motility. if (5 > 0.1 || v < -0.1 || h > 0.one || h < -0.1) { // rotate player towards the camera frontward. Vector3 european union = Photographic camera.main.transform.rotation.eulerAngles; transform.rotation = Quaternion.RotateTowards( transform.rotation, Quaternion.Euler(0.0f, eu.y, 0.0f), mTurnRate * Time.deltaTime); } } else { transform.Rotate(0.0f, h * mRotationSpeed * Time.deltaTime, 0.0f); } //transform.Rotate(0.0f, h * mRotationSpeed * Time.deltaTime, 0.0f); mCharacterController.Movement(transform.forwards * five * speed * Time.deltaTime); if (mAnimator != nix) { mAnimator.SetFloat("PosZ", v * speed / mRunSpeed); } // employ gravity. mVelocity.y += mGravity * Time.deltaTime; mCharacterController.Move(mVelocity * Fourth dimension.deltaTime); if (mCharacterController.isGrounded && mVelocity.y < 0) mVelocity.y = 0f; } }

Code language: C# ( cs )

ThirdPersonCamera.cs

          

using Organisation.Collections; using Arrangement.Collections.Generic; using UnityEngine; public class ThirdPersonCamera : MonoBehaviour { public enum ThirdPersonCameraType { Rails, Follow, Follow_TrackRotation, Follow_IndependentRotation, TopDown } public ThirdPersonCameraType mThirdPersonCameraType = ThirdPersonCameraType.Track; public Transform mPlayer; public Vector3 mPositionOffset = new Vector3(0.0f, 2.0f, -2.5f); public Vector3 mAngleOffset = new Vector3(0.0f, 0.0f, 0.0f); [Tooltip("The damping factor to smooth the changes " + "in position and rotation of the photographic camera.")] public float mDamping = one.0f; [Header("Follow Independent Rotation")] public float mMinPitch = -30.0f; public float mMaxPitch = 30.0f; public bladder mRotationSpeed = 5.0f; private float angleX = 0.0f; void Commencement() { } void Update() { } void LateUpdate() { switch (mThirdPersonCameraType) { case ThirdPersonCameraType.Track: { CameraMove_Track(); pause; } example ThirdPersonCameraType.Follow: { CameraMove_Follow(); break; } instance ThirdPersonCameraType.Follow_TrackRotation: { // refactored to non allow rotational tracking. CameraMove_Follow(truthful); break; } case ThirdPersonCameraType.Follow_IndependentRotation: { // refactored to not permit rotational tracking. Follow_IndependentRotation(); break; } instance ThirdPersonCameraType.TopDown: { CameraMove_TopDown(); pause; } } } void CameraMove_Track() { Vector3 targetPos = mPlayer.transform.position; // We removed mPlayerHeight and replaced with the mPositionOffset.y targetPos.y += mPositionOffset.y; transform.LookAt(targetPos); } // Follow camera implementation. // Refactored to allow only positional tracking or // positional tracking and rotational tracking. For this we // added a bool parameter called allowRotationTracking. void CameraMove_Follow( bool allowRotationTracking = false ) { // We apply the initial rotation to the camera. Quaternion initialRotation = Quaternion.Euler(mAngleOffset); // added the following code to allow rotation tracking of the actor // and so that our photographic camera rotates when the player rotates and at the same // fourth dimension maintain the initial rotation starting time. if (allowRotationTracking) { Quaternion rot = Quaternion.Lerp(transform.rotation, mPlayer.rotation * initialRotation, Time.deltaTime * mDamping); transform.rotation = rot; } else { transform.rotation = Quaternion.RotateTowards( transform.rotation, initialRotation, mDamping * Time.deltaTime); } // Now we calculate the camera transformed axes. Vector3 forwards = transform.rotation * Vector3.frontward; Vector3 right = transform.rotation * Vector3.correct; Vector3 up = transform.rotation * Vector3.up; // We then calculate the beginning in the // camera'southward coordinate frame. Vector3 targetPos = mPlayer.position; Vector3 desiredPosition = targetPos + forward * mPositionOffset.z + right * mPositionOffset.x + upwardly * mPositionOffset.y; // Finally, nosotros change the position of the camera, // not directly, but by applying Lerp. Vector3 position = Vector3.Lerp(transform.position, desiredPosition, Time.deltaTime * mDamping); transform.position = position; } void Follow_IndependentRotation() { float mx, my; mx = Input.GetAxis("Mouse Ten"); my = Input.GetAxis("Mouse Y"); // We utilize the initial rotation to the camera. Quaternion initialRotation = Quaternion.Euler(mAngleOffset); Vector3 eu = transform.rotation.eulerAngles; angleX -= my * mRotationSpeed; // We clamp the angle along the Ten axis to be between // the min and max pitch. angleX = Mathf.Clamp(angleX, mMinPitch, mMaxPitch); eu.y += mx * mRotationSpeed; Quaternion newRot = Quaternion.Euler(angleX, eu.y, 0.0f) * initialRotation; transform.rotation = newRot; Vector3 forward = transform.rotation * Vector3.forward; Vector3 correct = transform.rotation * Vector3.right; Vector3 upward = transform.rotation * Vector3.up; Vector3 targetPos = mPlayer.position; Vector3 desiredPosition = targetPos + forward * mPositionOffset.z + right * mPositionOffset.x + upwards * mPositionOffset.y; Vector3 position = Vector3.Lerp(transform.position, desiredPosition, Fourth dimension.deltaTime * mDamping); transform.position = position; } void CameraMove_TopDown() { // For topdown camera we do not use the x and z offsets. Vector3 targetPos = mPlayer.position; targetPos.y += mPositionOffset.y; Vector3 position = Vector3.Lerp( transform.position, targetPos, Fourth dimension.deltaTime * mDamping); transform.position = position; transform.rotation = Quaternion.Euler(90.0f, 0.0f, 0.0f); } }

Code language: C# ( cs )

Read Department three – 3rd-Person Camera Command in Unity for Android

Download the UnityPackage



Read My Other Tutorials

  1. Implement a Generic Pathfinder in Unity using C#
  2. Create a Jigsaw Puzzle Game in Unity
  3. Generic Finite State Machine Using C#
  4. Implement Bezier Bend using C# in Unity
  5. Create a Jigsaw Tile from an Existing Image
  6. Create a Jigsaw Board from an Existing Image
  7. Solving 8 puzzle problem using A* star search
  8. A Configurable Tertiary-Person Camera in Unity
  9. Player Controls With Finite State Machine Using C# in Unity
  10. Finite Land Motorcar Using C# Delegates in Unity
  11. Enemy Behaviour With Finite Land Car Using C# Delegates in Unity
  12. Augmented Reality – Fire Outcome using Vuforia and Unity
  13. Implementing a Finite State Motorcar Using C# in Unity
  14. Solving 8 puzzle trouble using A* star search in C++
  15. What Are C# Delegates And How To Employ Them
  16. How to Generate Mazes Using Depth-First Algorithm

Source: https://faramira.com/a-configurable-third-person-camera-in-unity/

Posted by: maciassonififf.blogspot.com

0 Response to "How To Rotate A Camera In Unity"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel