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 Bunzaga · Nov 12, 2012 at 03:19 PM · camerafollowfixedupdatesmoothfollowlateupdate

Camera Jitter using Fixed or LateUpdate, need it to be smooth in both.

I have a character the camera follows. All his movement code is in FixedUpdate, however there are times when he is on moving platforms that don't use the physics engine, they are just animated, and I parent the character to the platform.

The problem is, if I put the SmoothDamp on FixedUpdate, it works great for normal physics steps, but then the non-physics movement (like when attached to moving platforms) jitters and looks like trash.

If I move the SmoothDamp to LateUpdate (or Update), the physics movement jitters and looks like trash, but the movement while on the moving platforms looks nice and smooth.

I am assuming this is because they are updated differently within the engine. The moving platforms movement is handled automagically every Update, while the physics movement is handled in discrete increments.

I thought that using LateUpdate would resolve these kinds of issues... but it doesn't.

I also tried swapping around the script process order, as well as calling the camera movement from within the characters LateUpdate function, nothing seems to work at all.

On the other hand... If I don't use a SmoothDamp or Slerp / Lerp, the camera looks perfect when I use it in LateUpdate.

Here is my code:


function LateUpdate(){
	
	wantRotation = target.rotation;
	wantRotation.eulerAngles.x = eulerX;
	transform.rotation = wantRotation;
	
	wantPosition = target.transform.TransformPoint(positionOffset);
	
	transform.position.x = Mathf.SmoothDamp(transform.position.x, wantPosition.x, posDampVel.x, Time.deltaTime*7);
	transform.position.z = Mathf.SmoothDamp(transform.position.z, wantPosition.z, posDampVel.z, Time.deltaTime*7);
	transform.position.y = Mathf.SmoothDamp(transform.position.y, wantPosition.y, posDampVel.y, Time.deltaTime*10);	
}

Any help is more than welcome! :D

Comment
Add comment · Show 3
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 Kryptos · Nov 12, 2012 at 04:14 PM 1
Share

I don't think that this is a good idea to:

  1. Set the x-value of the eurer angles manually.

  2. Use another value than Time.deltaTime in the SmoothDamp function.

Anyway, LateUpdate is the correct method to deal with the camera position. So I think that your issue lies in the Update/FixedUpdate of the target object.

avatar image Bunzaga · Nov 12, 2012 at 04:59 PM 0
Share

1. The eulerX just stores the current eulerX of the camera. I guess I could replace:


wantRotation = target.rotation;
wantRotation.eulerAngles.x = eulerX;
transform.rotation = wantRotation;

With:


transform.rotation.eulerAngles.y=target.eulerAngles.y;

Essentially, the camera should follow the target at a set orbit, and distance.

2. $$anonymous$$aybe I am not using it properly then, I'll have to double check the API. From what I understand, you pass in the time you want the damp to happen over. So if I pass in .5, it will dampen over 1/2 a second. If you pass in Time.deltaTime, it will happen very fast, like each update. If you pass in a multiplier like I did, it will happen based on the framerate of the machine, but at a slower rate.

I'll recheck the API now.

avatar image Bunzaga · Nov 12, 2012 at 05:36 PM 0
Share

Yeah, I was using it wrong. You don't need to multiply the time by Time.deltaTime, you just pass in the time, and it does it for you. The issue still remains though.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunzaga · Nov 13, 2012 at 01:02 AM

Hey Kryptos, when you mentioned the rotation about the x axis, it made me start thinking that perhaps I should try to rotate to face the target differently.

This lead me to realize that the problem was that I was Dampening the camera position in the first place, rather than the offset based on the mouse. I needed the camera to remain in an explicit amount away from the 'target', however this wasn't possible because of the dampening effect, it would rotate to look at the target instantly, then take a bit to catch up to the proper position.

By setting the Euler angles manually, this problem was less apparent.

TL;DR: I had to SmoothDamp the offset, not the camera position itself.

Thanks for the help :D

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 Bunzaga · Nov 14, 2012 at 07:48 PM

There is still something not quite right about it... :(

It is mostly working, but when I move the mouse, or spin the character around, it jitters.

Here is my entire script, please let me know if you see anything that could be causing it...

#pragma strict // thing we are following public var target:Transform; // offset from target position public var targetOffset:Vector3 = Vector3(0.0, 0.0, 0.0); // orbit around target public var positionOffset:Vector3 = Vector3(0.0, 0.0, 0.0); // how much to scale the mouse offset by public var maxOffsetDistance:Vector2;

// DampVel variable private var posDampVel:Vector3 = Vector3(0.0, 0.0, 0.0); // multiplier to use for the mouse offset private var mouseMulti:Vector2; // amount we are away from center private var mouseOffset:Vector3 = Vector3(0.0, 0.0, 0.0); // the mouse offset we 'want' to get to private var wantMouseOffset:Vector3 = Vector3(0.0, 0.0, 0.0); // want position of camera private var wantPosition:Vector3 = Vector3(0.0, 0.0, 0.0); private var heightDamp:float = 0.0;

function LateUpdate(){ mouseOffset.x = (maxOffsetDistance.x/Screen.width)(Input.mousePosition.x-(Screen.width*0.5)); mouseOffset.z = (maxOffsetDistance.y/Screen.height)(Input.mousePosition.y-(Screen.height*0.5)); wantMouseOffset = Vector3.SmoothDamp(wantMouseOffset, mouseOffset, posDampVel, .3);

wantPosition = target.transform.TransformPoint(positionOffset+wantMouseOffset); wantPosition.y = Mathf.SmoothDamp(transform.position.y, wantPosition.y, heightDamp, .5);

transform.position = wantPosition; transform.LookAt(target.transform.TransformPoint(targetOffset+wantMouseOffset)); transform.rotation = Quaternion.Euler(transform.eulerAngles.x, target.transform.eulerAngles.y, transform.eulerAngles.z); }

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

10 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

Related Questions

how to make the camera follow the player only in one axis (the z axis) 0 Answers

Smooth Camera 2D Follow Player 0 Answers

[Closed] SmoothFollow trouble 0 Answers

How to Make the SmoothFollow Script Follow Faster? 1 Answer

A problem with an object following a player and camera? 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