• 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 /
  • Help Room /
avatar image
Question by pimdamen · Oct 12, 2018 at 11:19 PM · camera2d2d-platformercamera-movementplayer movement

If player hits certain X value in opposition to Camera, shift camera question.

As a beginner i encounter somet$$anonymous$$ng i am unable to figure out.

I thought i would be able to put the player object onder the Maincamera (Player_Cam) Than i have movement on the camera behavior script attacked to the camera. I set speed and a serialized field private gameobject called _playere. And put a sprite on it.

I want initially, to have the player under Camera walk to it's transform on X from starting -12f to -3.5f. After that set the _playerCenterStage to true and left to false. Now i want the player to still move, but now it's camera moving along with the player. so now i want the opposite effectright instead of running, to run left. If i am on the left side of the screen the player should not move but the camera should (as of the player was walking.) ...............

Come to t$$anonymous$$nk of it t$$anonymous$$s is silly w$$anonymous$$le i type it, the player would be held walking later on in place.

But i simply want the camera to follolw the player, only if player is in the center state. When he is left and walking right, move player but camera should stay still, intill centerstage is $$anonymous$$t When player is on center and moves left, center stage camera s$$anonymous$$fts so the plater will go in the rightside of the screen, andwhen player walks right again, stop camera untill he is center stage again.

What would be my best route?

Code so far that i need to redo.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Camera_Behavior : MonoBehaviour {
 
 

 [SerializeField]
         private GameObject _player;
         [SerializeField]
         private float _speed = 3f;
         private bool _playerCenterStage = false;
         private bool _playerLeftStage = true;
         private bool _playerRightStage = false;
     
         // Use t$$anonymous$$s for initialization
         void Start () {
             
         }
         
         // Update is called once per frame
         void Update ()
         {
             Movement();
             
         }
     
         private void Movement()
         {
             float HorizontalInput = Input.GetAxis("Horizontal");
             //float VerticalInput = Input.GetAxis("Verticle");
             if (_player.transform.position.x <= -12f || _playerLeftStage == true)
             {
                 _player.transform.Translate(Vector3.right * HorizontalInput * _speed * Time.deltaTime); //move
                 _player.transform.position = new Vector3(-12f, _player.transform.position.y, _player.transform.position.z); //move no further left
                 _playerLeftStage = true;
                 if (_player.transform.position.x == -3.5f)
                 {
                     _player.transform.position = new Vector3(-3.5f, transform.position.y, transform.position.z);
                     _playerCenterStage = true;
                     _playerLeftStage = false;
                     _playerRightStage = false;
                 }
                 if (_player.transform.position.x == -3.5f || _playerCenterStage == true)
                 {
                     gameObject.transform.Translate(Vector3.right * HorizontalInput * _speed * Time.deltaTime);
                 }
             }
         }
     
     
     }
 
 

and now as well for some odd reason whenever i start my game the _player objects s$$anonymous$$fts from the default -12F on x to -16 on the X and some even on the Y, w$$anonymous$$le i did tell it to.

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

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

cinemachine 2d look-ahead problem in respawn 2 Answers

2D box collider always detecting player,2D Box colliders detecting player when he is not there 1 Answer

Camera Oscillation problem 0 Answers

Cinemachine camera shake is changing layers of 2d objects 0 Answers

How to have your player controls change while your camera rotates? 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