Forum rules - please read before posting.

Moving an object only on one axis (2D PNC game)?

I'm looking for a way to move a dynamic object (teleport/transform) to a specific X coordinate so that its Y and Z coordinates would remain intact.

I know that I can target a specific axis by using Object>Transform and Translate>By and leaving the other values at zero. But this only helps me to move the object BY an amount. Using Translate>To and leaving the Y and Z at zero naturally sets them as 0. So how do I move the object TO a specific X coordinate without affecting Y and Z?

Comments

  • You can teleport an object a Marker's X position through script:

    using UnityEngine;
    using AC;
    
    public class MoveToMarkerX : MonoBehaviour
    {
    
        public Marker marker;
    
        public void Move ()
        {
            transform.position = new Vector3 (marker.transform.position.x, transform.position.y, transform.position.z);
        }
    
    }
    

    Attach to the object, fill in its Inspector, and use either the Object: Send message or Object: Call event Action to trigger the component's Move function.

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.