playMaker

Author Topic: How to store Vector3 of gameObject into variable?  (Read 1376 times)

thehay95

  • Playmaker Newbie
  • *
  • Posts: 1
How to store Vector3 of gameObject into variable?
« on: October 05, 2018, 04:38:43 PM »
I want to store the Vector3 of a gameObject in a variable, in this case, a respawn point, and set the position of my fps controller to that variable. I know that I should use the Get and Set position actions, but I'm not sure how they work. How would I go about doing this?
dich vu cham nguoi benh tai benh vien, cong ty https://giupviecnha24h.com/ gia re

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: How to store Vector3 of gameObject into variable?
« Reply #1 on: October 05, 2018, 05:31:02 PM »
Hello,

Try Get Position, then in the dropdown under Vector3, select new variable. This should store the transform.position (as you see in inspector in the top row) into a Vector3. You can then use this variable and Set Position at a later point. Make sure you use world space (i.e. not relative to parent objects).

Generally, don't hesitate to ask, but also just try things, you can't break much. :)

Another tip: save your scene, and make a new one. In the new scene, try out some actions in a very simple format. When trying things out, make the setup as simple as possible, using key down actions for convenience. For example, if you want to test out get and set position:

Add a cube. Attach a FSM to it. On start, get position, finish. In the next frame, use Key Down* (e.g. Tab), and hook this to a third state, set position. Hit play, observe the FSM doing the first state and waiting for the key down. Also click to the Variable pane, and onto the Vector3 and see if the values are changed. You can also click on Inspector, which shows it in the first FSM tab, as well as in the inspector FSM component. You can also click the cog icon above the variables and enable debug variables, which also shows all values currently stored (for all FSMs).

Now in the scene view, move the cube to some other position. Then hit Tab, and see if it jumps back to the position.


*For the actual game, consider using Input Manager, and Button Down actions.
« Last Edit: October 05, 2018, 05:34:53 PM by Thore »