playMaker

Author Topic: Get global position  (Read 134 times)

krmko

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • Fat Pug Studio
Get global position
« on: October 01, 2017, 10:29:34 AM »
Hi,

any chance of someone making this action? I've got a debug script for it, just needs to be put in an action, something i'm not quite confident in yet and i think it will be useful to many :)

Here's the script:

Code: [Select]
using UnityEngine;
 using UnityEditor;
 
 public static class DebugMenu
 {
     [MenuItem("Debug/Print Global Position")]
     public static void PrintGlobalPosition()
     {
         if (Selection.activeGameObject != null)
         {
             Debug.Log(Selection.activeGameObject.name + " is at " + Selection.activeGameObject.transform.position);

         }
Vector3 pos = Selection.activeGameObject.transform.position;
Debug.Log("pos is now " + pos.ToString("f3"));
     }
 }

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2252
    • View Profile
    • jinxtergames
Re: Get global position
« Reply #1 on: October 01, 2017, 06:49:27 PM »
Hi,
This is actually a 'Menu item'
so not usable for actions.
i am not sure what you are trying to do, but you could make something like this :

Have an fsm somewhere and in the 1st state have a "on mouse Down" then on the next state have a mouse pick to select the object.
then you can use get position and set space to "world" next you can use debug actions or whatever you need to do (for example 'add to array list')
then after you done what you need to do, use a next frame event and loop back to the 1st state.

krmko

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • Fat Pug Studio
Re: Get global position
« Reply #2 on: October 09, 2017, 06:58:56 AM »
It is a menu item, but the logic is the same. Transform panel in the inspector shows the local position of the object, you have to deparent it to see its global position which is stupid.

Thanks for the tip, but it's too complicated, i'll try making and sharing an action :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Get global position
« Reply #3 on: November 02, 2017, 12:16:09 AM »
Hi,

 can you explain your use case?

 the problem is that you are mixing editor tools with runtime tools, so this action will not work when you pubish it. You may have a good use case though, maybe you want to save data at edit time to use for level edition or something.

 bye,

 Jean