Greetings everyone!
its my first game in unreal engine (using 5.1) I am new to blueprints and engine but I have been learning a lot about it. so I managed to get the paddle to work and move it to where I want using convert mouse location to worldspace , as seen below: https://blueprintue.com/blueprint/02j968x_/
(i used this website for easy way to read/look into my blueprint pawn class, the paddle. )
anyway is this method good? or should I use the “Get Input Touch State” node? because I want to move multiple paddles later on like a local multiplayer on same mobile device (red vs blue).
also there is another method which is “Get hit result under cursor for objects” node but I am really struggling with these both methods to make it work probably because I don’t know where should I write my functions also don’t know how to connect them probably to make it work like I want haha, should I write it in the game mode class bp? because I want to create player vs AI mode and later on local multiplayer mode on same device!
you could just use GetHitResultUnderCursor by Channel
then all u need is plug in your player controller and you wont need a line trace as its built into the function. then do your branch and break hit the same as you already have!
hey! @High500 thanks for helping me will do it! btw I heard that its better to use “Get hit result under cursor for objects” rather than channel so the actor doesn’t jitter sometimes when its moved
ok that understandable, but whichever way works best for you, i really dont think either way will impact the stability or playability so it really is a matter of “what works works”
ok do u know how should I go about it? also should I write in the pawn bp(the paddle) or in the game mode bp for later when I wanna do local multiplayer on same device to control both paddles with touch!
also how do i clamp the paddle movement to a certain area? what i mean when the paddle reaches to the center of the table it wont go any further!
i think the player pawn BP can handle its own inputs best, that emans all players are set up when their pawn is spawned. , never done it on mobile, but im guessing it should work the same as long as the device supports multi touch.
Also you answered you own question about the limits
Use a clamp node, u might have to break each vector out from the touch position into floats, then clamp the min max for each axis. There is a clamp vector but i think the same value is used for all axis. so clamp the x to the mid point of the table and the bottom and the y value to the left and right sides of table.
Remember to take into account the width of the paddle when doing the clamps so they dont over hang. but you will realise that anyway when you play around with the settings.
Now for how do I control other pawn with finger touch 2?
btw what do you mean by “all players are set up when their pawn is spawned” I tried give each pawn player input 1 and the other pawn player 2 and went inside each bp and changed it its player controller index + finger index but still i couldn’t make them move (both of them stopped working and the log showed me error after I clicked stop).
Can you please show me how do I use clamp node with this example? because I don’t see the touch position vector in my above bp functions, am I missing something?
You clamp works on the break hit location you are using for movement, so split the pin or use break vector then clamp each x y z as u need .
As for the other player what inmeant is the touch controls are there but how do u differentiate between players.
Easiest way is make sure you dont consume inputs then give each player an area they can touch for play , detect those touches and split them so if touch is on player 1 side of the table then move the pawn, if on player 2s side that moves their pawn , simple bounds check. Tho touch on 1 device for 2 players isnt gonna be easy.
I have no idea how this works on mobile devices im afraid so im breaking it down using logic. The inplementation you will need to figure out
I figured it out! i limited my area and worked as i wanted it, thanks!!
Now For the two players… i need to figure it out let me know what do you mean by dont consume inputs? and how do i do it “give each player an area they can touch for play” ? sorry i am still new to these stuff haha
Ok consume inputs is a tick box on the enhanced input system. If you untick it for each input action for touch, then ALL players will receive ALL touches.
Then to filter out unwanted touches per player. Detect which side of the board they are on.
Work out their BOUND AREA (ie their side of table) and only process if it falls inside.
BUT like ibsaid i dont use mobile so i havent a clue of its workings for touch. But my head is over thinking it probably and the fact that you cast down to check if you on the paddle then surely it shouldnt matter. As long as you allow multi touch it will work.
Im guessing you get a finger id?
So if you do, on touch started get the id, set a boolean to say player 1 got his paddle.
On tick check the positions of finger id 1 and move the paddle. Then on the action completed turn off the boolean and ignore inputs
hey! I used enhanced input system inside my pawn bp (the paddle) but its not working anymore? see my bp here: https://blueprintue.com/blueprint/k0var69_/
Am I missing something here? why it stopped working now?
It was working perfectly fine before I implemented enhanced input system (btw it was recommended by @High500 so I can untick consume inputs and filter out unwanted touches per player).
I am gonna use trigger volumes on each side of the table and then reference them to get their bounds. after I use “get actor bounds” node which nodes should I connect to it to process and detect which side of the table the finger touch was on? then I will give each paddle a finger id so that each paddle knows when to move and when it shouldn’t. The goal here is to move multiple paddles at the same time with multi touch!
*If you are over thinking my issue! lets forget its a mobile game for now think it like its a PC game using mouse cursor to play.
**btw with enhanced input system I can give/add any key or touch whether its keyboard, a controller or mouse inside the action input it gonna work and it doesn’t matter right so why you overthinking things?! haha only how you write your functions matters!
So ok have you mapped your enhanced system to the local player subsystem?
That will show you how inside your paddle (or player controller!)
so the basics what you need:
detect a touch (doesnt matter which finger (or mouse))
does it raycast hit your paddle?
if it does set a boolean to remember you have grabbed the panel. no need to check again if it hasnt, so on started set true, on completed set false. Also have another Var for the finger ID so an int will do. set it by detecting WHICH finger grabbed paddle.
have a routine ontick check
a: is the finger touching boolean true?
b: is the finger id you want currently moving? (or just get the position constantly and
update your paddle)
if both are true, move your paddle (you only need to detect 1 axis left<>right!)
that means you paddle will only move to the captured finger position if its still touching
btw @High500 what do you recommend to put the camera (as the camera is top down view to my hockey table) should I leave it as pawn that is not signed elsewhere or should I add camera within the player controller bp class or should I add the camera component in the viewport of the game mode class instead?