Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by awplays49 · May 26, 2015 at 07:05 PM · playermouselookjerky

Camera movement (or something else in this script) causing somewhat jerky movement

Hi,

I have been developing a top down 3D game, and I just noticed a slight jerky movement where the camera jerks back a little when moving for a long period of time. This is repetitive and the time between each jitter seems to be the same every time.

Here is my code:

 using UnityEngine;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour {
 
     public float moveSpeed;
     private Vector3 mousePos;
     public Animator anim;
     private bool canWalk;
     
     void Update () {
         mousePos = Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y - transform.position.y));
         transform.LookAt (new Vector3 (mousePos.x, transform.position.y, mousePos.z));
         if (Vector3.Distance (transform.position, mousePos) >= 2.5f)
         {
             canWalk = true;
         }
         if (Vector3.Distance (transform.position, mousePos) <= 1)
         {
             canWalk = false;
         }
         if (canWalk == true)
         {
             if (Input.GetKey (KeyCode.W) && GameObject.Find ("Control Manager").GetComponent <ControlManager> ().moveEnabled == true)
             {
                 GetComponent <CharacterController> ().Move (transform.forward * moveSpeed * Time.deltaTime);
                 anim.SetInteger ("Direction", 1);
             }
             else
             {
                 anim.SetInteger ("Direction", 0);
             }
         }
         else
         {
             anim.SetInteger ("Direction", 0);
         }
         Vector3 playerXZ = new Vector3 (transform.position.x, Camera.main.transform.position.y, transform.position.z);
         Vector3 velocity = Vector3.zero;
         Camera.main.transform.position = Vector3.SmoothDamp (Camera.main.transform.position, playerXZ + Vector3.back * 3.75f, ref velocity, 0.05f);
         GetComponent <CharacterController> ().Move (Vector3.up * Physics.gravity.y * Time.deltaTime);
     }
 }

I think it's the smoothdamp at the bottom, but I can't be sure. the smoothdamp target offset has to do with the angle of the top down camera, in case anyone wasnt aware. It's looking down at a 75 degree angle, which is 15 from looking straight down, so I moved the camera back a little so the player would be centered...

I think it's either the fact that the player is moving, stopping when close to the mouse, and moving again, or the player's camera is jerky. ANY help will be acknowledged and appreciated.

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

19 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

Related Questions

Lock camera (on) ontriggerenter 1 Answer

Camera rotating the player on the z axis 0 Answers

why is "lock cursor" on "FPS controller" not working? 0 Answers

Help|MouseLook Y-Axis moving in the wrong direction 1 Answer

How to disable Mouselook with the new Unity 5? 1 Answer


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