Createing a touch and drag interface in the 3d world
I am trying to create a 3d card game for mobile devices. Currently I am in the process of creating an interface to move playing cards through 3d space in the game using a touch screen. When I get the value of the touch input it gives me a 2d vector based on the screen and I can convert that vector to real 3d space. The problem is I had to offset the values I get from the input to match the true location in the game. This presents a problem for multiple sized screens. So far here are the numbers I am working with....
Screen (width / height): 905/431
The movement variance is the number of units the card moves in real 3d for every one unit of touch. I need to find some sort of calculation to scale these values to any screen size but I am stumped. I will add some pictures to help make sense of this.
I would appreciate any input. Including a better way to use a touch interface all together. I would have imagined an easier to use touch interface system but I guess not. Maybe some way to actually link to 3d space built into the editor. I can get it to work fine on any one specific size but I need a way to scale it no matter what device people play on. If there is no way to scale accurately I guess I can use a table of values but lets try to avoid that...
asked Dec 18 '15 at 05:43 AM in Blueprint Scripting
I do everything in world space instead of screen space.
The first step is in my player controller, I use the input touch event. When it is pressed, I take the hit from Get Hit Result Under Finger By Channel, then I break the hit, and cast the hit actor to my object to be dragged (in your case this would probably be a card actor base class) If the cast succeeds, then I know the user touched the object to be dragged (in your case a card) and I set a dragging bool to true (this gets set to false on touch release of course) lastly, I set a reference variable for the dragging object (you can get this from your broken hit, hit actor)
Then in the tick event (I also do this in the player controller), if the dragging bool is true, I simply set the actor location of the dragging object to the location of the broken hit. This may not be needed for you, but I also break the location vector and strip out the Z value, and replace it with a hard coded value so everything always stays on the same plane.
Hope this helps!
answered Dec 31 '15 at 06:41 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here