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 Chaos Warp · Mar 06, 2013 at 06:21 AM · cameratutorialsburgzergarcade

My camera stays in the same position regardless of any variables I change

I am following Burgzergarcade's tutorials and I think the camera position and angle are being set both in the GameMaster script and the HackandSlashCamera script. I am just trying to make the camera start in a different spot behind the player but no matter what I comment out or change the camera stays in the same spot.

here is the code for the GameMaster script:

 using UnityEngine;
 using System.Collections;
 
 public class GameMaster : MonoBehaviour {
     public GameObject playerCharacter;
     public GameObject gameSettings;
     public Camera mainCamera;
     
     public float zOffset;
     public float yOffset;
     public float xRotOffset;
     
     
     private GameObject _pc;
     private PlayerCharacter _pcScript;
     
     private Vector3 _playerSpawnPointPos;            //this is the place in 3d space where I want my player to spawn
     
     // Use this for initialization
     void Start () {
         _playerSpawnPointPos = new Vector3(35, 5, 120);            //the default position for our player spawn point
         
         GameObject go = GameObject.Find(GameSettings.PLAYER_SPAWN_POINT);
         
         if(go == null){
             Debug.Log("Can not find Player Spawn Point");
             
             go = new GameObject(GameSettings.PLAYER_SPAWN_POINT);
             Debug.Log("Created Player Spawn Point");
             
             go.transform.position = _playerSpawnPointPos;
             Debug.Log("Moved Player Spawn Point");
         }
         
         _pc = Instantiate(playerCharacter, go.transform.position, Quaternion.identity) as GameObject;
         _pc.name = "pc";
         
         _pcScript = _pc.GetComponent<PlayerCharacter>();
         
         zOffset = 2.5f;
         yOffset = 2.5f;
         xRotOffset = 22.5f;
         
         mainCamera.transform.position = new Vector3(_pc.transform.position.x, _pc.transform.position.y + yOffset, _pc.transform.position.z + zOffset);
         mainCamera.transform.Rotate(xRotOffset, 0, 0);
         
         LoadCharacter();
     }
     
     public void LoadCharacter() {
         GameObject gs = GameObject.Find("__GameSettings");
         
         if(gs == null) {
             GameObject gs1 = Instantiate(gameSettings, Vector3.zero, Quaternion.identity) as GameObject;
             gs1.name = "__GameSettings";
         }
             GameSettings gsScript = GameObject.Find ("__GameSettings").GetComponent<GameSettings>();
                         
             //loading the character data
             gsScript.LoadCharacterData();
     }
 }




here is the code for the HackandSlashcamera script:

 using UnityEngine;
 using System.Collections;
 
 public class HackAndSlashCamera : MonoBehaviour {
     public Transform target;
     public string playerTagName = "Player";
 
     public float walkDistance = 4;
     public float runDistance = 6;
     public float height = 4;
     public float xSpeed = 250.0f;
     public float ySpeed = 120.0f;
     public float heightDamping = 2.0f;
     public float rotationDamping = 3.0f;
     
     private Transform _myTransform;
     private float _x;
     private float _y;
     private bool _camButtonDown = false;
 
     void Awake(){
         _myTransform = transform;    //cache our transform so we do not need to look it up all of the time
     }
     
     // Use this for initialization
     void Start () {
         //if we do not have a target, let them know, else set the camera up according to where our target is.
         if(target == null)
             Debug.LogWarning ("We do not have a target for the camera");
         else {
             CameraSetUp();
         }
     }
     
     void Update(){
         //detetct if the player has entered any input
         if(Input.GetMouseButtonDown(1)) {    //Use the Input Manager to make this user selectable button
             _camButtonDown = true;
         }
         if(Input.GetMouseButtonUp(1)) {     //Use the Input Manager to make this user selectable button
                 _camButtonDown = false;
         }
     }
     
     
     //this function is called after all of the Update functions are done
     void LateUpdate(){
 
         if(target !=null) {
             if(_camButtonDown){
             _x += Input.GetAxis("Mouse X") * xSpeed * 0.02f;
             _y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f;
          
 //             y = ClampAngle(y, yMinLimit, yMaxLimit);
                 
             Quaternion rotation = Quaternion.Euler(_y, _x, 0);
             Vector3 position = rotation * new Vector3(0.0f, 0.0f, -walkDistance) + target.position;
             
             _myTransform.rotation = rotation;
             _myTransform.position = position;
         }
         else {
             _myTransform.position = new Vector3(target.position.x, target.position.y + height, target.position.z - walkDistance);
             _myTransform.LookAt(target);
             _x = 0;        //reset the x value
             _y = 0;        //reset the y value
                 
                 
             // Calculate the current rotation angles
             float wantedRotationAngle = target.eulerAngles.y;
             float wantedHeight = target.position.y + height;
         
             float currentRotationAngle = transform.eulerAngles.y;
             float currentHeight = transform.position.y;
     
             // Damp the rotation around the y-axis
             currentRotationAngle = Mathf.LerpAngle(currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);
 
             // Damp the height
             currentHeight = Mathf.Lerp(currentHeight, wantedHeight, heightDamping * Time.deltaTime);
 
             // Convert the angle into a rotation
             Quaternion currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);
     
             // Set the position of the camera on the x-z plane to:
             // distance meters behind the target
             _myTransform.position = target.position;
             _myTransform.position -= currentRotation * Vector3.forward * walkDistance;
 
             // Set the height of the camera
             _myTransform.position = new Vector3(_myTransform.position.x, currentHeight, _myTransform.position.z);
     
             // Always look at the target
             _myTransform.LookAt (target);                        
         }
     }
         else {
             GameObject go = GameObject.FindGameObjectWithTag(playerTagName);
             
             if(go == null)
                 return;
             
             target = go.transform;
         }
 }
     
     public void CameraSetUp(){
         _myTransform.position = new Vector3(target.position.x, target.position.y + height, target.position.z - walkDistance);
         _myTransform.LookAt(target);
     }
 }
 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Chaos Warp · Mar 06, 2013 at 11:40 PM

Nevermind, the code for the camera is in both scripts so I just commented one out and started to fix the other.

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

10 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

Related Questions

Camera control of Tanks! tutorial..... 1 Answer

How to make camera position relative to a specific target. 1 Answer

Camera Falling when I press play. 0 Answers

Scripting question 3 Answers

Accessing all GameObjects with a certain tag 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