Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 1234filip · Jun 20, 2017 at 09:19 AM · rotationcamera rotaterotate objectjitterjittering

Jittering effect when moving character and camera

Hey!
I want to make a game and I wrote some code that really suits my needs but I'm having a problem. When I'm moving the character and the camera at the same time I get this really weird jitter effect. When I'm moving only the camera or the character I don't get this. Here is my code for the camera:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class MouseLook : MonoBehaviour
 {
 
     public float speedH = 2.0f;
     public float speedV = 2.0f;
 
     private float yaw = 0.0f;
     private float pitch = 0.0f;
 
     public Transform tran;
     //This tran is the character transform
 
 
     // Use this for initialization
     void Start()
     {
 
     }
 
     // Update is called once per frame
     void Update()
     {
 
         yaw += speedH * Input.GetAxis("Mouse X");
         pitch -= speedV * Input.GetAxis("Mouse Y");
 
         transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
         tran.rotation = Quaternion.Euler(0, yaw, 0);
 
     }
 }
 

And this is the character code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerMove : MonoBehaviour {
 
         public float speed;
 
         private Rigidbody rb;
         private Transform tr;
 
         void Start()
         {
             rb = GetComponent<Rigidbody>();
             tr = GetComponent<Transform>();
         }
 
         void FixedUpdate()
         {
             float moveHorizontal = Input.GetAxis("Horizontal");
             float moveVertical = Input.GetAxis("Vertical");
 
         rb.MovePosition(tr.position + (tr.right * moveHorizontal * (speed * 0.01f) + (tr.forward * moveVertical * (speed * 0.01f))));
 
     }
 }
 

So I tried a lot of stuff but nothing works. How do I make this work without jittering? EDIT: Here is the gif of the jittering. Look at the cube. You don't see it when the gif is small. Just zoom in the page. http://imgur.com/6yChVjI

Comment
Add comment · Show 4
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 SohailBukhari · Jun 20, 2017 at 09:38 AM 0
Share

it seems to work fine for changing Update to LateUpdate.

 void LateUpdate()
      {
          yaw += speedH * Input.GetAxis("$$anonymous$$ouse X");
          pitch -= speedV * Input.GetAxis("$$anonymous$$ouse Y");
  
          transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
          tran.rotation = Quaternion.Euler(0, yaw, 0);
      }
avatar image 1234filip SohailBukhari · Jun 20, 2017 at 09:47 AM 0
Share

No It's still jittering

avatar image SohailBukhari SohailBukhari · Jun 20, 2017 at 10:14 AM 0
Share

rotate eulerAngles using Time.deltaTime

 void Update()
      {
  
          yaw += speedH * Input.GetAxis("$$anonymous$$ouse X");
          pitch -= speedV * Input.GetAxis("$$anonymous$$ouse Y");
  
          transform.eulerAngles = new Vector3(pitch, yaw* Time.deltaTime, 0.0f);
          tran.rotation = Quaternion.Euler(0, yaw, 0);
  
      }
avatar image 1234filip SohailBukhari · Jun 20, 2017 at 10:59 AM 0
Share

Now it doesn't rotate the camera and when it does it shakes like crazy.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by 1234filip · Jun 20, 2017 at 04:55 PM

I found a solution. Instead of rotating the camera on the y axis and then rotating the character, I rotated the character directly on the y axis and camera on the x axis. Of course the camera must be a child of the character.

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
avatar image
0

Answer by GilbertoBitt · Jun 20, 2017 at 05:41 PM

for what i see i'm pretty sure that u r setting the rotation, location of the camera directly on it! u should use some sort of lerp to smooth the movement of the camera to where player is, or to the specific rotation that u desire and this will create a smooth transition and remove the jittering.

here some link that can help u!

Lerp Like A PRO

Comment
Add comment · Show 3 · 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
avatar image 1234filip · Jun 20, 2017 at 05:58 PM 0
Share

I lerped like you said but it's still jittering. Here's my look script now:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class $$anonymous$$ouseLook : $$anonymous$$onoBehaviour
 {
 
     public float speedH = 2.0f;
     public float speedV = 2.0f;
 
     private float yaw = 0.0f;
     private float pitch = 0.0f;
 
     public Transform tran;
 
     float lerpTime = 1f;
     float currentLerpTime;
     //This tran is the character transform
 
 
     // Use this for initialization
     void Start()
     {
 
     }
 
     // Update is called once per frame
     void Update()
     {
 
         yaw += speedH * Input.GetAxis("$$anonymous$$ouse X");
         pitch -= speedV * Input.GetAxis("$$anonymous$$ouse Y");
 
 
 
 
         //reset when we press spacebar
         if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))
         {
             currentLerpTime = 0f;
         }
 
         //increment timer once per frame
         currentLerpTime += Time.deltaTime;
         if (currentLerpTime > lerpTime)
         {
             currentLerpTime = lerpTime;
         }
 
         //lerp!
         float perc = currentLerpTime / lerpTime;
 
 
 
 
         transform.eulerAngles = Vector3.Lerp(transform.eulerAngles, new Vector3(pitch, yaw, 0.0f), perc);
         tran.eulerAngles = Vector3.Lerp(tran.eulerAngles, new Vector3(tran.rotation.x , yaw, tran.rotation.z), perc);
 
 
     }
 }

avatar image 1234filip · Jun 20, 2017 at 06:13 PM 0
Share

$$anonymous$$ake the camera movement on LateUpdate, this also helps to remove this kinds os problems.

avatar image 1234filip · Jun 21, 2017 at 09:00 AM 0
Share

It didn't work like in the previous reply

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

86 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

Related Questions

Set rotation is jittering back to original rotation 2 Answers

How to account for situation using RotateAround 0 Answers

fixed rotation around object 1 Answer

Drag Rotation Objet Snapping to 0,0,0 on new drag. 0 Answers

Object won't rotate 2 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