playMaker

Author Topic: How to set position of an Empty Game Object based on touch position?  (Read 3077 times)

Adam Z

  • Full Member
  • ***
  • Posts: 207
I have a state with a 'Touch Event'. I also added a 'Get Touch Info' to store the touch location into a variable. I was storing it in a Vector3, but I only want to store the X and Z axis, not the Y.

On my Empty Game Object I have a 'Set Position', with Vector grabbing the position based on the Vector3 as above.

This works, except it's also including the Y position.  How can I set this up so I only get the X and Z position? The 'Get Touch Info' doesn't allow me to specify a Z axis so that doesn't help. Maybe I change change the world coordinates and switch the Z and Y?

Thanks!
« Last Edit: May 08, 2013, 10:39:27 PM by adamzeliasz »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 you'll need to extract the X and Y value into separate FsmFloats, and then set the X and Z of another vector with them X and Y. After that, you can inject that other vector as the position of your gameObject.

 yes, you can also rotate the whole scene by 90, but I would not recommand it.

bye,

 Jean

Adam Z

  • Full Member
  • ***
  • Posts: 207
I'm still not following...

I have a Empty Game Object that spawns the dice. This needs to have it position set by the location of the touch.  On this Game Object I have a 'Set Position'.

I have two states for the die "dropper":
A Wait state which has a 'Touch Event'; Begin Touch Phase, Send Event Roll.

A Roll state which has a 'Create Object', my die as the Game Object, and the Empty Game Object as the spawn point.  Then I have a 'Touch Event' with End that goes back to Wait.

On the Wait state I need to detect the location of the touch. I thought about using 'Get Position' but that seems to work on game objects. What action should I use?

Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 you are facing a common problem. Touch position are express in screen coordinates, and to translate a touch position into a 3d world position, you need to first define the rule of conversion, because the touch is missing the depth.

 Likely, you want to project the touch position onto a fictive 3d plane in your world, for this I created a custom action to let you define that conversion and get a 3d world position based on a 2d screen position:

http://hutonggames.com/playmakerforum/index.php?topic=272.0

the action is called "mouse3dDrag" but you can inject any screen position, simply get touch position instead of the mouse position.

bye,

 Jean