• News

• Industries

• Learning & Support

• Community

• Marketplace

# How to get the relative position of the Input Touch State?

Hello

In my 3D tower defense mobile game, in can move around the base, and rotate the base on itself with the touch screen !

But when I move around the base, the left and right movement remains valid and the up and down movement is reversed!

Is there a solution to this problem?

I am using this code for the rotation of the base:

Hi man, that was a tricky question!!
you can make a custom rotator, using the camera vectors.
I made a quick test and seem work correctly.

Hi @Est_engine !

I tried like your example with the mouse and in another way with the input touch but nothing works.

To explain further, the player controls a sphere placed inside the base (his heart)
I donâ€™t know if the problem is that the camera is inside the Blueprint pawn controlled by the player

I also tried using a widget to detect finger position on the screen but it also didnâ€™t work.

Hi @Ptiflodu85
lets split up the problemâ€¦

you have a Blueprint Heart with inside a camera ,
and another actor called frame_blueprint that is the actoryou want to rotate
Correct?

You can correctly rotate the camera around the target .

set onl the mouse X to add a actor world rotation on the target, using the :
Rotation from axis - camera right vector.

now try to run the simulation and check from every possible angle, if the rotation applied
is always relative to the camera.

is the target rotating always the same ?
is the target rotating always different ?
is the target rotating relatively to the cam ?
If rotate in wrong direction you have to multiply the mouse axis value for -1

Hi @Est_engine
First, thank you for your time !

Yes my setup is like that.

I do not rotate exactly the camera around the target, i rotate all the blueprint Heart and so his camera with him.

With this code (itâ€™s not me who does it)

And when the Input Touch is detected on the base, the code in the BluePrint Heart is disabled so that the rotation applies only at the base.

I tried what you told me about itâ€™s two ways, and nothing works:

I also try this, and the values are in any case always equal to 0:

Hi man,
you need to link the mousex axis value to the angle value
for this i think it does not move , because he add a rotation of 0 !

I tried like that and the result is the same, no movement of the base.

I see with the Event Tick and the Mouse X Axis Value is also always equal to 0

Ok we got the problem .
As you can see , my test can see the mouse x even when i unplug everything.
so we must discover why you dont see mouse X !

I just notice that you have 0,0,0 when you print the camera right vector, that not possible too !
if the camera exist , must have a orientation , and cant be 0,0,0 at least is 1,0,0

Lets split the problem

Try making a new clean blueprint, with a camera and print the mouse x and the camera vector right.
If you dont see values, there is something in the project that we must fix, or some other stuff like blueprint that absorb the events.

To be mega-sure make a new level and try there the new blueprint.

Ok, then inside the blueprint heart where the camera is, I find its values print on the screen with the camera Right Vector

But if I test with the mouse X of the same way, the value remains always at 0.
Maybe the problem comes from the fact that itâ€™s a mobile game project and I do not have an Input Mouse from Set in the Project Settings ?

Because if instead of the â€śMouse Xâ€ť I use the â€śGet Input Touch Stateâ€ť in the level BluePrint, I correctly get the X and Y location of my input on the screen (and so of my mouse).

I have a standard project clean and neither i have set the mouse mapping.
But for me works fine

Anyway lets try to have this work,
Get yourself the difference between the mouse coordinates at every tick and apply the rotation like before but inputting you the value.

So
At every tick , get the input state x and y, subtract this value from the older xy, this is â€śvalueâ€ť
now add rotation world-make rotator from axis- pin in the â€śValueâ€ť .
Save the x y as old xy

This time you should get the rotation

Ok so, with this function, i get the coordinates of the mouse

But for the rest I have to admit that Iâ€™m a bit exceeding, can you explain to me with an example in picture because Iâ€™m really trying to understand but Iâ€™m lost.

is very simple, @Ptiflodu85
Now that you can see the mouse value, you have to identify the value of the motion.
as you can see from the print , the tick event run at 60-100 time for seconds
and he print all the positions 100,100, 102,100, 105,100â€¦
what you want to do is understand of how much it change for every tick.

So when you start the movement, Maybe with the rightmousebutton
you create a variable to store the mouse position in that moment. â€śMouseStartPosâ€ť
Now in the tick event, you can understand of how much you moved by subtracting the new position to the old position of the mouse.
if was 100,100, and now is 120,80â€¦
in this tick you moved of +20 x, -20y
if you did not move the mouse for some tick, the numbers wil be the same and the result is 0
so no rotation when you dont move.

Now you can apply the rotation with the make rotation from axis, using the camera and using this value X for rotate the base on z , and the value of y, to rotate the base on the other axis.

Do not forget that before the tick ends,
you must record the new mouse position as the â€śStartMousePosâ€ť
So the next tick will take on from there,

Ok so,
I store the mouse position when i start the input.

At each Tick, I subtract the current position of the mouse to its old position. And at the end of the tick i record the new position as the â€śMouseStartPosâ€ť

What should I do now with the camera knowing that Iâ€™m in LevelBlueprint and I can not get the Vector Right values from the camera that itâ€™s in the BP_heart?

from level blueprint,
get a reference to your Bp_heart.

if you have only 1 BP of this kind you can use
get actor of class, to get a ref to him
With the ref at hand you can set the variable inside that actor or even call events.

if you have his reference in the form of an actor reference
than you can use â€ścast-toâ€ť- heart-bp
and by that , do the same.

So i would create a variable inside heart-bp
that contain a 2d vector , for value x and y
lets call it MouseMoved_xy

Level blueprint will constantly set the variable
inside that actor with the value you just calculated, so the subtraction of the positions of the mouse.

so now you can use this variable with the make rotation from axis and plug the mouseMoved_xy to the value

Hi

IT WORKS !!!
I finally managed to recover all the values in the Level Blueprint (Mouse Position, Vector Camera, the Object to rotate).
Thank you for your time and all explanations, may God bless you and your lineage.