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 rumpletuffin · Feb 13, 2014 at 02:48 PM · camera movement

I am having a problem with trying to get the camera to follow the main character.

I have entered this code into monodevolp: #pragma strict

 var target = Transform;
 var distance = -10;
 var lift = 1.5;
 var BuildTarget = "MainCharacter";
 
 function Update () 
 {
     transform.position = BuildTarget.position + Vector3(0, lift, distance);
     
     Transform.LookAt ("MainCharacter");
 }

and I am getting these errors:

Assets/CameraControl.js(12,26): BCE0023: No appropriate version of 'UnityEngine.Transform.LookAt' for the argument list '(String)' was found.

Assets/CameraControl.js(10,42): BCE0019: 'position' is not a member of 'String'.

I am rather new to the unity system so thanks for your help!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by instruct9r · Feb 13, 2014 at 03:25 PM

What are you doing is that you are passing a String, to the LookAt. What is "MainCharacter"?

First of all you realy have to learn to declare the type of the variables, this will speed up your code reading a lot.

 var distance : float = -10;

etc.

What does the target variable holds? What is this Transform? Target from the name shoud be the object, that the camera shoud be following. First of all you can't search for a name of an object like (Variable = "MainCharacter".

If you character is named "MainCharacter" then your code shoud be something like this:

     var target : Transform = GameObject.Find("MainCharacter");
     var distance : float = -10;
     var lift : float = 1.5;
   //  var BuildTarget = "MainCharacter";  // You don't need this, since you have the target...
      
     function Update () 
     {
         transform.position = target.position + Vector3(0, lift, distance); // We set the chamera to follow the target position
      
         Transform.LookAt (target); // LookAt is looking at transform, not at String.
     }
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 MadMapp · Feb 13, 2014 at 03:32 PM

 var distance: int = -10;
 var lift: float = 1.5;
 var BuildTarget = Tramsform;
  
 function Update () 
 {
     transform.position = BuildTarget.position + Vector3(0, lift, distance);
  
     Transform.LookAt (BuildTarget);
 }

you had build target set to be a type of string by placing comments on it "" in the var declaration, ive changed it to a type of Transform, just drag the "mainCharcter" in to the BuildTarget variable in the inspector also correctly declared your variables as an int and float type you may want to replace BuildTarget with another name... like "player"

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 vwh · Feb 13, 2014 at 03:22 PM

As you can see in the documentation here, the LookAt() function expects either an object (the target) or a position as its parameter. Here your variable is a String so "BuildTarget.position" is not defined either. The easiest way to fix your problem is to affect your BuildTarget variable the actual object. You can do so by using the Unity interface via a simple drag and drop, or in your code by setting the variable from another script, or even by using Find:

 BuildTarget = GameObject.Find("MainCharacter");

However, if you do use the Find function, just make sure to store the value once and then keep reusing the same variable, instead of calling it every frame (for performance reasons).

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

21 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Please Help !, camera rotation 1 Answer

Orientation of Vector3.forward 1 Answer

GearVR, Using Swipe to control Camera in VR 0 Answers

How can I make the camera follow the player's rotation only on the z axis? 1 Answer

How to stop the player rotation after i stop the 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