Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 lucashaley · Mar 01, 2011 at 06:16 PM · cameracamera-movementsmoothdamp

Camera Dampening

Heya all --

I'm trying to add dampening to a side-scrolling camera. Here is my code attached to the camera:

var smoothTime = 0.3; var cameraDampening = 10.0; var target:Transform; var newPositionX:float; var newPositionY:float;

function FixedUpdate () { newPositionX = Mathf.SmoothDamp(transform.position.x, target.position.x, cameraDampening, smoothTime); newPositionY = Mathf.SmoothDamp(transform.position.y, target.position.y, cameraDampening, smoothTime);

 transform.position = Vector3(newPositionX, newPositionY, transform.position.z);

}

But what happens is that going left and right makes the camera go up and down, and vice versa. It seems like I've switched the axes, but I'm not seeing where. Any help?

Thanks so much!

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 owenpat · Mar 02, 2011 at 02:27 AM 0
Share

$$anonymous$$ake another var named cameraDampeningY and use it for Y. The problem is that cameraDampening is used to "remember" the speed you are moving. when you reuse it for x, then y, it gets jerked around trying to move both ways. Each SmoothDamp needs its own var for the 3rd "speed" input. The solution below, Vector3.SmoothDamp, does this automatically (the third input is a Vector3, which is X's, y's and z's speed all in one.)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by lucashaley · Mar 01, 2011 at 06:56 PM

I tried this instead, and it works pretty well:

function Update () {
    // smoothing
    transform.position = Vector3.SmoothDamp(transform.position, target.position, velocity, smoothTime);
    // clamp z position for side-scrolling
    transform.position = Vector3.Scale(transform.position, Vector3(1, 1, 0));
}

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

No one has followed this question yet.

Related Questions

Smooth camera shift, Lerp? SmoothShift? 2 Answers

2D Camera Smooth follow, FixedUpdate and LateUpdate odd difference, help needed. 1 Answer

Smoothly zoom object at point or camera boundaries 2 Answers

Sketchup-style camera movement/rotation?. 0 Answers

I can not find Cinemachine in package manager. There is no option of 'All Assets in package manager.' 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