Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
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 something 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 think of it this is silly while 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 hit When player is on center and moves left, center stage camera shifts 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 this 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 shifts from the default -12F on x to -16 on the X and some even on the Y, while i did tell it to.

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

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.

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

How to make camera follow player from point to point 2 Answers

Camera flickers while chasing the player 0 Answers

C# Script On Camera Hides Player? 1 Answer

Mouvement issue with mouse input. 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