How do I make code not work on a child
I want my player to look right when you press the right arrow key and left when you press the left arrow key The catch is the camera is a child of the player, and it flips the camera's Z axis. I want the camera's position on the z axis to stay the same. How do I do that??
note it's a 2D game
Answer by MFen · Jan 21, 2016 at 03:49 PM
I'm guessing you want the camera to follow player but not receive rotations, what I've done in the past is create my own parenting script, basically a simple Update the sets the position of the "child" with an offset based off the parent. e.g.
using UnityEngine;
using System.Collections;
public class Testing : MonoBehaviour
{
public GameObject parent;
public Vector3 offset;
void Update ()
{
transform.position = parent.transform.position + offset;
}
}
Your answer
Follow this Question
Related Questions
How do I make the character rotate with the 2D camera? 0 Answers
2D Smooth Camera Movement 1 Answer
Camera movement 1 Answer
Camera Movement Panning with middle mouse 1 Answer
2D movement with gravity shifting 0 Answers