Forum rules - please read before posting.

NPC as child of a rotated Transform is rotating wildly.

Hi,

so I run into the issue where I want to place an NPC at the end of a rope and I want to add a swinging motion to the rope (beside the rope swinging motion the NPC is static and not moving anywhere).

My hierarchy is: Rope -> NPC.
As soon as I slightly rotate the NPCs parent (the rope) the NPC rotates like wild. How can I prevent that?

Please help.

Best!
Alex

Comments

  • Is it the NPC's root rotating like wild, or their sprite child?

    You can try unchecking Turn root object in 3D? in their Inspector, but it'd probably be best to rely on a script to snap their position/rotation to the rope through script as opposed to parenting them:

    using UnityEngine;
    using AC;
    
    public class PositionSetter : MonoBehaviour
    {
    
        public Transform positionReference;
        public Transform rotationReference;
        public Transform transformToPosition;
        public Transform transformToRotate;
        private bool isOn;
    
        private void Update ()
        {
            if (isOn)
            {
                if (positionReference && transformToPosition) transformToPosition.position = positionReference;
                if (rotationReference && transformToRotate) transformToRotate.rotation = rotationReference;
            }
        }
    
        public void TurnOn ()
        {
            isOn = true;
        }
    
        public void TurnOff ()
        {
            isOn = false;
        }
    
    }
    

    To use this, attach to the NPC as PositionSetter.cs, fill in its Inspector fields, and then use the Object: Send message Action to call its TurnOn/TurnOff functions.

  • Hi!

    It is the SpriteRenderer Child of the NPC. Happens with in any fresh created scene and NPC - no custom behaviour.
    Turn root object in 3D doesn't change it. I tried other options too.

    I am on AC 1.75.4

    It would be nice to be able to set the NPC as child of an object just for convenience but I understand that it might cause problems. I thought about resetting the localRotation in a LateUpdate but it is another hack - and I try to avoid these ;)

  • Thanks for the details.

    The script above is probably your best bet, then. All of the Inspector fields are optional - so you need only supply Transforms to affect the rotation if needed.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.