Forum rules - please read before posting.

Question about Object Transform - Record Global Position

Hi there!

I'm almost done with the first game I started creating in Adventure Creator.

I've decided to develop some new systems for a new game that I plan to start soon. One particular system I want to implement is a two-way portal system that can be placed anywhere in any scene, allowing teleportation back and forth between two locations.

I understand how to set up most of it, but I’m unsure how to store the position of a portal once it has been placed. Since the scene reference needs to be dynamic, I was considering using "Object - Record Transform" when placing the portal and then using "Variable Check - Global Variable" (also used in Record Transform).

Would this approach work for what I’m trying to achieve?

My plan is to create an inventory item that can be grabbed and dragged into a scene, possibly using Inventory Interaction or Unhandled Inventory Interaction. Inside this, I would place an Action List that records the location via a Global Variable (Vector3) and then sets variable checks with "Object - Teleport to Marker (Is Player)".

Would this be a good way to achieve this, or is there a better approach?

Thank you in advance!

Comments

  • If the item you place down is unique (i.e. one instance per scene), then you can attach a Marker as a child to that item's prefab, as well as a Constant ID component with Retain in prefab? checked. That will assign it an ID value that's consistent each time it's placed down.

    You can then run an Object: Teleport Action, affecting the Player, that references the prefab's Marker. This will record the ID value, causing it to search for that ID within the scene at runtime.

    For spawning in the item, the built-in way is to assign the prefab as the item's Linked prefab, and then use the Inventory: Scene item Action. A tutorial on this can be found here.

  • Hi Chris! Thanks for replying back so quickly. There's going to be two unique items that are going to be constantly used. Portal A and Portal B. A leads to B, B to A. The part I'm having trouble with is when I switch Rooms. For example if Portal B is in Scene 1 and Portal A is in Scene 2, or 3, or whatever. So with that said, would hwat you suggested still work? Thank you again!

  • You could record the current scene index as an Integer variable, and then use it to override the Scene: Switch Action as a parameter, but I wonder if this could also be done with Player-switching.

    Essentially: create a Player named e.g Player_B, and when placing down Portal B, use Player: Teleport inactive to place Player_B at a Marker attached to Portal B's prefab. Then when you enter Portal A, run Player: Switch to switch to Player_B.

  • The Hi Chris! Thanks again for the reply. That's the part I'm confused about how to record that interger value in a scene. Does that need to be done via Scene Attributes? If so, how do you link that Scene Attribute Integer to The Global variable?

  • You could do it with a script attached to the spawned prefab:

    using UnityEngine;
    using AC;
    
    public class SetSceneIndex : MonoBehaviour
    {
    
        public string variableName;
    
        void Start ()
        {
            GlobalVariables.GetVariable (variableName).IntegerValue = gameObject.scene.buildIndex;
        }
    
    }
    
  • Thank you @ChrisIceBox . Have a wonderful rest of the weekend.

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.