• 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
Question by Darkhour99 · Oct 04, 2013 at 06:50 PM · camerajavascriptfollowsmooth2.5d

Having issues with a smooth camera follow

I'm trying to create a smooth camera follow for a 2.5D game (plays like 2d, is in 3d). Im having issues though as my camera follows the character too well even when I'm pretty sure it shouldnt be (and by shouldn't I mean I've drastically changed the numbers involved to warrant a difference). The translation for both the camera and the character are nearly the same, even when I've tried to severely lower or raise the camera speed. Maybe my math or logic is bad but I've worked it out several times and it still seems like it should work. Maybe someone can take a look at it for me and offer some advice.

http://pastebin.com/NX88tzcB

Comment

People who like this

0 Show 0
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
Best Answer

Answer by robertbu · Oct 04, 2013 at 07:24 PM

First, if you past your code directly into the question (and format it using the 101/010 button), you are likely to get a much better response.

I made a quick pass through your code. It seems like an awfully complicated way to do smooth camera tracking with easing. There may be something specific you are getting out of it that I don't see. Here is an alternative script that tracks an object on the XY but leaves 'Z' alone. It attaches to the camera and expects the tracked object to be named "Player". But you can take the same logic and integrate into a 3-party script like yours:

 #pragma strict
 
 private var player : Transform;
 var deadZone = 0.15;
 var speed = 1.5;
 
 function Start () {
     player = GameObject.Find("Player").transform;
 }
 
 function Update () {
     var v3 = player.position;
     v3.z = transform.position.z;
     if (Vector3.Distance(v3, player.position) > deadZone)
         transform.position = Vector3.Lerp(transform.position, v3, speed * Time.deltaTime);
 }
Comment
DylanW

People who like this

1 Show 1 · 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 Darkhour99 · Oct 04, 2013 at 08:32 PM 0
Share

Wow, thanks. That's exactly what I needed and way simpler. I should really research things before hacking them together.

avatar image

Answer by Krey · Oct 04, 2013 at 07:36 PM

From what I can tell, you are turning the distance to move into an incredibly small number...

It looks like the maximum difference that the camera trails by is .1f (deadZone). You're then taking .1f^camSpeedCoef, which turns it into .0000000001f.

Multiplying the character's speed by Time.deltaTime ensures that you're getting fractional numbers unless the speed is very high.

Comment

People who like this

0 Show 0 · 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.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

Smooth Follow Rotation 3 Answers

Smoothly following a moving object 5 Answers

How to get smooth camera movement with smooth follow? 0 Answers

Camera Smooth Follow 2 Answers

Modified SmoothFollow 0 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