• 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 daemonfire · Nov 18, 2010 at 06:47 PM · cameravector3camera-movement

Camera moves into Object instead of following

hi there,

I got the following code: It's my camera class, following an object, ignoring the y-Rotation, ideal for a game that just follows one direction, like mine. Now, the "Distance" gets smaller, that means the camera moves into the object, and I have absolutely not idea why it does that.

using UnityEngine;

using System.Collections;

public class StaticCamera : MonoBehaviour

{

 public Transform Sph;

 public Vector3 pSph;

 public float height = 10f;

 public float distance = 10f;

 public float Dampening = 1f;



 void LateUpdate()

 {

     pSph = Sph.position;



     float desHeight = pSph.y + height;

     float curHeight = transform.position.y;



     curHeight = Mathf.Lerp(curHeight, desHeight, Time.deltaTime *Dampening);



     transform.position = pSph;

     transform.position -= Vector3.forward * distance;

     transform.position += new Vector3(0,desHeight,0);

     //transform.Translate(0,curHeight*Time.deltaTime,0);

     /*

      * float desX = Mathf.Lerp(transform.position.x, Sph.position.x,Dampening*Time.deltaTime);

     float desZ = Mathf.Lerp(transform.position.z, Sph.position.z,Dampening*Time.deltaTime);

     transform.position = new Vector3(desX,0f+15f,desZ);

     */

     //Quaternion rtn = Quaternion.Euler(15,0,15);

     //transform.rotation = Quaternion.Slerp(gameObject.transform.rotation, rtn, Time.deltaTime*10);

     transform.LookAt(Sph);

     Debug.Log("Distance: " + Vector3.Distance(gameObject.transform.position, Sph.position));

 }

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by daemonfire · Nov 18, 2010 at 07:02 PM

Goch, found the problem. Even though height, etc. were set inside the script the editor had overwritten it to zero =) This explains a lot of "bugs" to me now. Man, I was totally broken, because Vector3.up * height (=10f) returned (0,0,0).

Comment

People who like this

0 Show 2 · 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 Proclyon · Nov 18, 2010 at 07:25 PM 0
Share

Oh yeah we all remember one of those mistakes all right :D The classic "I can't believe that THAT was the error" errors

avatar image by0log1c · Mar 03, 2011 at 03:52 PM 0
Share

Yeah, that's something we all learned the hard way: Inspector values override scripts' values.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How do I program camera movement 2 Answers

Move camera when mouse is near the edges of the screen 1 Answer

My game is laggy, but there are only a ball and some flat platforms. 3 Answers

camera script not working 1 Answer

Free Orbit Cam and Mouse Aim Cam aren't working together 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