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

Hello :raising_hand_man:t4:

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?

Enregistrer l'Ă©cran 2021-04-13 Ă  12.01.24 2

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


Hi @Ptiflodu85

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 :man_shrugging:t2:

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…

first, your setup ,
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:


Enregistrer l'Ă©cran 2021-04-14 Ă  12.01.28 2

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

Capture d’écran 2021-04-14 à 12.22.48

Hi man,
you need to link the mousex axis value to the angle value
this is your screenshot, see the missing link?
for this i think it does not move , because he add a rotation of 0 !
https://d3kjluh73b9h9o.cloudfront.net/uploads/default/original/3X/9/c/9ce57fa285728b023e88949be1495f6bdcb9e507.png

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
Capture d’écran 2021-04-14 à 14.53.01 Enregistrer l'écran 2021-04-14 à 14.50.59

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 :+1:
Capture d’écran 2021-04-15 à 10.13.03 Enregistrer l'écran 2021-04-15 à 10.11.54

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 :+1:t3:
Capture d’écran 2021-04-15 à 21.20.25 Enregistrer l'écran 2021-04-15 à 21.19.19

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”

Enregistrer l'Ă©cran 2021-04-17 Ă  12.26.24

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 :raising_hand_man:t4:

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.
Enregistrer l'Ă©cran 2021-04-19 Ă  12.36.43