Transform.position affected by children

Hello everyone.

For my game, I’m trying to animate a simple cursor. The cursor consists on two parts:

The first part it’s a static square-like object which highlights a tile in my grid

The second part it’s a glove-like object, going up and down somewhere above the first object.

I’ve set up a simple prefab to do so, I’ve done it like this:

  • I’ve got two sepparate meshes, one for the square, called “square” and the other for the glove, called “glove”, they’re parented to the same gameObject, called “Cursor”.

  • Next, i set up a simple script, here it goes: EDIT: (Note that this script is attached to the glove, not to the parent, otherwise my question would make no sense at all)

    public class CursorAnimation : MonoBehaviour {

     public float Amplitude = 1.0f;
     public float frequency = 1.0f;
     public float yRotateSpeed = 1.0f;
     
     // Update is called once per frame
     void Update () {
     	transform.position += new Vector3(0, Amplitude*Mathf.Sin(frequency*Time.time),0);
     	transform.Rotate(new Vector3(0,0,yRotateSpeed));
     }
    

    }

However, this isn’t working, because while being static, the cursor behaves as it should, but when moving the glove up and down, it somehow modifies the position for the “Cursor” parent object, which seems to adapt to the average position between the square and the glove rather than being static, making movement impossible.

I don’t know what I’m doing wrong, I thought modifying the glove’s position would only affect it’s relative position to the parent but it’s actually affecting the parent as well, I can’t really see what’s going on, some help would be much appreciated.

Thank you very much.

Well, this seems to be only happening when dragging the object around in scene mode, the center pivot point is moving because it tries to stay at the center, and with the actual center moving, the handle moved as well, but the position itself isn’t modified. Although, when dragging from the inspector, with the handle moving at the same time as it was being used, it caused some weird issues to happen with the position of the cursor. So It seems it’s an editor issue. EDIT: Changing the tool handle from “center” to “pivot” solved the problem

PD: I can’t tell right wether if using transform.localPosition helped or not, I think it works with both, but using transform.localRotation seemed to make more sense to me.

Any more answers or added info on this are welcome, as I’m not going to mark my own answer as good (at least I’ll wait a little more).