• 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 Leafenzo · Feb 08, 2019 at 04:40 AM · rotationoffsettranslationparent and child

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();
 }
Comment
Add comment · Show 1
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 Chimer0s · Feb 08, 2019 at 10:28 AM 0
Share

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?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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;

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 Leafenzo · Feb 08, 2019 at 10:41 PM 0
Share

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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

135 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

Related Questions

Stop camera from moving when parent rotates forward 1 Answer

Smooth transform position and rotation 1 Answer

How to rotate the camera around an object 2 Answers

How to move an object a fixed distance along one of its axis 1 Answer

Transform.LookAt() when transform.forward is offset 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges