• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by bdweidner · Nov 02, 2017 at 03:08 AM · cameracamera-movementsmoothlaggy3rd person camera

My camera is not smoothly following my character

I am creating a 3D game and I have just recently implemented a camera that follows the player. The camera will shift once the player reaches a certain end of the screen, so the camera isn't completely fixed, but rather follows the character around. However, when the camera begins to shift to follow the player, it seems to be a bit laggy and not smooth. I have pasted the scripts I have used for both my Camera setup as well as movement function for my character, just in case the problem might lie there (without the camera setup it seems smooth but just in case).

CameraRigTarget attached to an empty object to set a position for the camera

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class CameraRigTarget : MonoBehaviour {

 public GameObject focusPoint;
 public Vector3 offset;

 private void Start()
 {
     offset = this.transform.position - focusPoint.transform.position;
 }
 // Update is called once per frame
 void Update () {
     this.transform.position = focusPoint.transform.position + offset;
 }

}

SmoothTargetMovement follows the character

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class SmoothTargetMovement : MonoBehaviour {

 public Transform target;
 public float speed;
 public float threshold = 0.01f;

 // Use this for initialization
 void Start () {
     
 }
 
 // Update is called once per frame
 void Update () {
     Vector3 difference = target.transform.position - this.transform.position;
     if (difference.magnitude > threshold) {
         Vector3 direction = difference.normalized;
         Vector3 movement = direction * speed * Time.deltaTime;
         if (movement.magnitude > difference.magnitude)
         {
             this.transform.position = target.transform.position;
         }
         else
         {
             this.transform.position += movement;
         }
     }
 }

}

Walk character movement

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Walk : MonoBehaviour {

 public float dSpeed = 1.5f;
 public float dAngleSpeed = 5f;

 private Rigidbody rbody;

 // Use this for initialization
 void Start () {
     Debug.Log("Walk Start");
     rbody = GetComponent<Rigidbody>();
 }

 // Update is called once per frame
 void Update() {
     var newvel = new Vector3(0f, 0f, 0f);
     var curspeed = dSpeed;
     if (Input.GetKey(KeyCode.W)) // move forward
     {
         if (Input.GetKey(KeyCode.LeftShift)) // run
         {
             Debug.Log("Sprinting");
             curspeed += 2f;
         }
         newvel += (transform.forward * curspeed);
     }
     if (Input.GetKey(KeyCode.S)) // move backward
     {
         newvel -= (transform.forward * curspeed);
     }

     rbody.velocity = newvel;


     if (Input.GetKey(KeyCode.D)) // rotate right
     {
         transform.Rotate(0, dAngleSpeed, 0);
     }
     if (Input.GetKey(KeyCode.A))  // rotate left
     {
         transform.Rotate(0, -dAngleSpeed, 0);
     }
 }

}

I would really appreciate any help anyone could offer, any insight as to what the problem is, or if there are any decent tutorials that anyone could point me to. Thank you!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pineco222 · Nov 13, 2021 at 02:19 PM 0
Share

You should move you character in FixedUpdate() and try interpolation for RigidBody

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Vadol · Nov 02, 2017 at 03:53 AM

Try Vector3.Lerp

 this.transform.position = Vector3.Lerp (this.transform.position, focusPoint.transform.position, speed);
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

161 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make camera follow player from point to point 2 Answers

Making a Smooth camera zoom with transform.Translate 1 Answer

SmoothCameraCrouch 2 Answers

moving the camera smoothly to players current position in unity 2 Answers

Why is my camera shaking when I use my chaser script on something? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges