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 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
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
1
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
Add comment · 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
0

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
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

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

Camera follow smoothness problem 1 Answer

Smooth Follow Problem 1 Answer

Why does the camera smoothly follow in one direction but not the other? 0 Answers

[Closed] SmoothFollow trouble 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