- Home /
Child cannot be offset from parent.
-Edit- So I don't actually need help, there's plenty of workarounds and I've used one of them, I'm just wondering why in the world this would happen just out of curiosity.
Hi so this question is probably me missing something terribly obvious, but I have been trying to crack it for about 5-ish hours now. I have a rotating object that rotates to point at the mouse. I'm trying to attach a transform to it that I can offset forwards a bit that will rotate along with it. The problem I'm having is that anything I attach to it becomes locked in place, and cannot be offset from this parent. No objects are static, the moving transform has nothing in it, no rigidbodies. Once the object is a child, it literally cannot move, and it's no script moving it.
As I try to move it with the inspector, I can put in new coordinates and the number does change. But in the scene view, it's location does not. I also tried moving it with the move tool just in the scene as well, and it gets selected where it looks like it is, but the It can't be moved. Trying to move it that way does not change the coordinates.
My best guess so far is that it's the rotation code, but I did try one other variant of it and that didn't help any either. This seems like a really dumb problem, is there something really obvious that I missed?
I just can't move it with the inspector controls. Here's the following code (Tested with and without the other parts of it of course.)
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PcharaFacer : MonoBehaviour {
private GameObject thisPlayer;
private Camera cam;
private GameObject attatchedCameraRig;
private void Start() {
thisPlayer = this.transform.parent.gameObject;
attatchedCameraRig = thisPlayer.transform.Find("CameraRig").gameObject;
cam = attatchedCameraRig.GetComponentInChildren<Camera>();
}
public float Rotoffset;
private void Update ()
{
Vector3 difference = cam.ScreenToWorldPoint(Input.mousePosition) - transform.position;
float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.Euler(0f, 0f, rotZ + Rotoffset);
//findRotationzone();
}
Not seeing anything in the code that jumps out to me as the problem. Have you tried removing/disabling the script first to make sure that it's actually what's causing the issue?
Answer by blueshark- · Feb 08, 2019 at 08:58 PM
You could try to create a new game object, name it Player for example and put all the objects inside with the needed offset etc. Make sure the position of the Player GO is (0,0,0) and create a prefab. This should keep the offset of all the objects.
Otherwise you could make a variable objOffset and do camera.transform.position = player.transform.position + objOffset;
The main problem I'm having is not offsetting the object against the player, I"m trying to rotate a child around the rotating parent object as it rotates. Although I would figure out how to do that eventually, I would like to be able to do that just with the offset. I'm really just confused about the reasons why a child would lock up like this.
Your answer
![](https://koobas.hobune.stream/wayback/20220612191334im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Instantiated object's transform changes according to parent object's rotation 1 Answer
Move object forward relatively to itself 3 Answers
Translate and rotate at the sametime problem 1 Answer
How to get find euler angle provided I have Transformation Matrix 1 Answer
Limit Rotation of Camera around a player using keyboard 1 Answer