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 kinggamer1235 · Sep 07, 2014 at 01:10 PM · cameraplayer2d-platformercamera rotateflip

camera rotating with player

I am making a simple 2D platformer where you have to find all the keys to unlock a door. I am trying to make the player flip over when i move right or left and have succeeded but whit one problem.

My camera is a child of my player so when the player flips using this code:

 f(Input.GetKey(KeyCode.D))
         {
             rigidbody2D.velocity = new Vector2 (speed, rigidbody2D.velocity.y);
             transform.eulerAngles = new Vector2(0, 0);
         }
         else if(Input.GetKey(KeyCode.A))
         {
             rigidbody2D.velocity = new Vector2 (speed*-1, rigidbody2D.velocity.y);
             transform.eulerAngles = new Vector2(0, 180);
         }

The camera flips along with it which complete messes up the game!

How can i stop this from happening? Thanks in advance!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Dipetriantonio · Sep 07, 2014 at 01:32 PM

If you have the camera as a non child object and add a camera script like:

 using UnityEngine;
 using System.Collections;
 
 public class CameraScript : MonoBehaviour {
 
     public GameObject target;
 
     // Use this for initialization
     void Start () {
         target = GameObject.FindGameObjectWithTag("Player");
     }
 
 void Update(){
     Vector3 tempPos = target.transform.position;
     tempPos.x = tempPos.x + offsetX;
     tempPos.y = tempPos.y + offsetY;
     transform.position = tempPos;
     transform.LookAt(target.transform.position);
 }

The offset variables can be whatever fits your game. Then you just drag your player gameobject to the empty target slot in the camera script in the inspector when the camera is selected. You also need to select the tag "Player" for your character object.

Hope that helps!

Comment
Add comment · Show 1 · 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 kinggamer1235 · Sep 13, 2014 at 06:46 PM 0
Share

cannot implicitly change unityengine.gameobject[] to unityengine.gameobject.

something along those lines i am really stuck

avatar image
0

Answer by malekbakeer · Sep 07, 2014 at 01:39 PM

click on (Assets > Import Assets) Click On the Camera Scripts

and remove the camera from the player's child

then Select your Camera and click on (Components > Camera > SmoothFollow) or (Components > Add Component > Camera > SmoothFollow) and change the numbers as you like (The Higher The Less Smooth)

Good Luck :D

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Camera problem 2 Answers

How to rotate camera diagonally over players shoulder while still facing towards players direction 0 Answers

Player's movements doesn't match orbital camera 1 Answer

Character Controller Help. 1 Answer

How to rotate smoothly behind target? 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