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
1
Question by numberkruncher · Feb 09, 2012 at 05:24 AM · camera2.5dcamera-scrolling

Smoother camera movement?

I have written a custom camera follow script which deals with specific requirements within my game. The camera smoothly tracks the player position, however surrounding geometry appears to "jitter" and the further away geometry is, the worse the problem appears.

I understand why this happens, moving the camera a little close up makes a larger jump further away.

What can I do to minimize this undesired effect?

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

2 Replies

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

Answer by DevonJavaScript · Feb 09, 2012 at 05:56 AM

In my experience with this the main problems come from either Lerping or the Function the lines are contained in:

Steps to Make Movement smooth:

1) Lerp positions:

 var nextPosition: Vector3; //or public Vector3 nextPosition; if in C#
     var moveSpeed: float; //or public float moveSpeed; if in C#
    transform.position = Vector3.Lerp(transform.position, nextPosition, Time.deltaTime * moveSpeed);

2) Use an Update function instead of LateUpdate or FixedUpdate:

  function Update()  //Or void Update() if in C#

3) Use Time.deltaTime as its smoother than Time.time:

 Time.deltaTime;

I really hope I could help be sure to ask if any further Questions.

Comment
Add comment · Show 6 · 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 numberkruncher · Feb 09, 2012 at 03:00 PM 0
Share

Okay, having made that change the camera is now moving beautifully....but, now the player is jittering. The player has a rigidbody and is moving via the rigidbody velocity. cheers

avatar image numberkruncher · Feb 09, 2012 at 03:01 PM 0
Share

To clarify, I have added Vector3.Lerp. I was already using Update...I didn't even know of FixedUpdate so I will read into that. Any ideas for smoother player movement would be brilliant thanks again

avatar image DevonJavaScript · Feb 09, 2012 at 10:16 PM 0
Share

Try to stay away from Rigidbody controllers, I wrote a character movement script for you were you only need to attatch the Character Controller script: private var moveDir: Vector3; private var CurrentSpeed: float = 0.0; var RunSpeed: float = 8.0; var WalkSpeed: float = 6.0; var JumpSpeed: float = 12.0; var gravity: float = 20.0; function Update () {

   //Toggle Run
   if(Input.GetButton("Run")){
      CurrentSpeed = $$anonymous$$athf.Lerp(CurrentSpeed,RunSpeed, Time.deltaTime * 3.5);
    }else{
      CurrentSpeed = WalkSpeed;
    }
    var controller : CharacterController = GetComponent(CharacterController);
     grounded = controller.isGrounded;
     
     //the meat of the script
     if(controller.isGrounded){
   
        moveDir = Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
        moveDir = transform.TransformDirection(moveDir); //How to move
        moveDir *= CurrentSpeed;
        if(Input.GetButton("Jump")){
         moveDir.y = JumpSpeed;
         }
     }
     controller.$$anonymous$$ove(moveDir * Time.deltaTime);
   
     moveDir.y -= gravity * Time.deltaTime;
 
 }
avatar image numberkruncher · Feb 10, 2012 at 01:16 AM 0
Share

Wow, my player is moving very nicely now! Except, now my player has no RigidBody, how can it collide with things? I am making a side-scroller shooter which has various obstacles, walls, etc. I haven't applied a CharacterController because the properties did not seem relevant for my character. How come the RigidBody causes such jittering? I really appreciate your help

avatar image DevonJavaScript · Feb 10, 2012 at 05:51 PM 1
Share

Yeah! Just with the Character Controller the Controller Acts as a collider, so if you goto unity documentation you can look at character controller and look at its functions and see it also returns as a collider. You can call the collider functions with the function just as most functions for collision do!

Show more comments
avatar image
1

Answer by Vishwa001 · May 26, 2017 at 08:15 PM

Best way to smooth camera movement in untiy2D..

transform.position=Vector3.SmoothDamp(new Vector3(transform.position.x,transform.position.y,-10f), new Vector3(player.transform.position.x,player.transform.position.y,-10f), ref velocity, smoothTime);

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

8 People are following this question.

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

Related Questions

How to create an old school camera switch when the player leaves/enters camera view 1 Answer

2.5D lighting looks wrong when rotating camera 0 Answers

2.5D Shooter Rescrict Movement to Camera View 2 Answers

How do I implement this Camera Tracking? 0 Answers

Need to Find Distance Between Mouse Cursor and Object in a 2.5D SideScroller 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