Hello everyone,
I have a little problem, I want to move a child without moving his parent, I thought it was automatic but it doesn’t work so I think I misunderstood the link between parent and child… =/
Here my problem:
Camera is the parent
MainCamera is the child
CameraController (Script) controls Camera (the parent)
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
public float speedTranslation = 4f;
public float speedRotation = 10f;
private Vector3 dir;
// Update is called once per frame
void Update () {
dir = Vector3.zero;
if (Input.mousePosition.x < 10f || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.Q)) {
dir += Vector3.left;
}
else if (Input.mousePosition.x > 1910f || Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) {
dir += Vector3.right;
}
if (Input.mousePosition.y < 50f || Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) {
dir -= Vector3.forward;
}
else if (Input.mousePosition.y > 850f || Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.Z)) {
dir += Vector3.forward;
}
transform.Translate (dir.normalized * speedTranslation * Time.deltaTime);
if (Input.GetKey(KeyCode.A)){
transform.Rotate (Vector3.down * speedRotation * Time.deltaTime);
}
else if (Input.GetKey(KeyCode.E)){
transform.Rotate (Vector3.up * speedRotation * Time.deltaTime);
}
}
}
CameraControllerRotationUpDown (Script) is link with MainCamera (the child)
using UnityEngine;
using System.Collections;
public class CameraControllerRotationUpDown : MonoBehaviour {
public float speedRotation = 10f;
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.KeypadPlus)) {
transform.Rotate (Vector3.left * speedRotation * Time.deltaTime);
}
else if (Input.GetKey (KeyCode.KeypadMinus)) {
transform.Rotate(Vector3.right * speedRotation * Time.deltaTime);
}
}
}
But when I rotate the child, the parent rotates too and i don’t want it. Can you help me?