UPDATE 03/02/2015: Since starting to work with Paper2D I have found there to be less support and documentation for it as first thought. I have decided to continue with the same concept however I will be doing it in a 3D plane with normal blueprints from now on.
Hello all,
I am working on a small game which involves throwing balls across a plain. The central mechanism is after selecting the ball you want to throw, you pull away with the mouse, aim, let go and watch it fly. Very early as you can see below, the tip of the arrow is where the cursor has been pulled to create a slingshot type action.
I am having two initial problems with this:
First it is the slingshot indicator which I want to have reset once the player has let go of the ball so they can choose another one. What seems to happen is if the player was to select a different ball then the first ball would still show an slingshot attached and ends up having multiple selections at the same time.
The ball will be destroyed once it leaves the screen however I can still see this problem interfering especially when it comes to throwing the object which brings me onto the second issue:
I need the ball to be thrown however the blueprint I have made does not seem to throw the it away. I have added an impulse and the ball is a physics actor in the world but does not respond to the impulse. I have no need for a variation in how fast the ball is thrown so the cursor can be anywhere on the screen but it is important the it be thrown in the opposite direction of where the cursor is. The closest example I can think of is the catapult used in Angry Birds.
When I think about it out loud the concept seems to be really simple but I just cannot get my head around the scripting. Can anybody help?
Thanks in advance
EDIT: There are some errors appearing in the image however these all disappear once the blueprint is compiled.
I think I can see what your first problem is. When you click the first ball, you set that bool ‘IsCursorOverBall’ to true, and every frame you check that bool and whether the player is pressing left mouse button. After the first ball is thrown, it’s bool is still set to true, and it’s still checking every frame to see whether the player has pressed left mouse button. When the player selects the second ball, suddenly the conditions for the first ball are true for both branches (since the bool was not reset) and so the slingshot is drawn again.
There are events for OnReleased, onBeginCursorOver and onEndCursorOver (I believe that’s their names) which you might be able to use to detect whether the cursor is still over the ball. Hopefully that’s a shove in the right direction!
Unfortunately I’ve got little experience with the physics - all I can say is check that simulate physics is ticked somewhere in the balls components.
I did try the OnReleased event but the cursor needed to be over the ball in order for it to let go of the ball. I guess in a way I am trying to get either the tick event to reset within the blueprint or have it so that the IsCursorOverBall bool becomes false so that the first branch stops proving true.
I will experiment a little with some of the other click events and see how that goes. Thanks for the advice!
Basically, there’s a bool that stores whether the cursor is over the actor, just like yours, but it’s set onCursorOver and EndCursorOver. The logic is such that if the mouse ever leaves the actor, then my custom onReleased event is called, and I treat leaving the button the same as having released the mouse click.
Thanks for the advice, I’ll give it a go as soon as. Can I ask and excuse my ignorance but what are the type functions being called with the envelope on the right? I don’t think I recognise them.
Those are custom event dispatchers. When I create my buttons using ‘Spawn Actor from Class’, I ‘bind’ custom events to these event dispatchers, and when the event dispatcher is executed, anything ‘bound’ to them also executes. It lets me bind different results to my buttons without having to create lots of different buttons
I should maybe point out that the example I gave was just what worked for my setup - the interesting thing for you is what events set the bool and the fact that the cursor leaving the actor is treated as an actor onReleased event.
Hi StomachBug, sorry if I’m hijacking your thread, but I didn’t find another way to reach you.
Can you share your slingshot controls blueprint graph? I’m trying to do something similar but I haven’t succeeded yet, I’m interested to see how you’ve done it. Thanks in advance.
You are right about the onReleased event because it will only return a result if the cursor is still over the actor. I am trying to think of a way to incorporate the Is Input Down function to apply to the OnReleased event.
Sure no problem at all. I think it has the potential to be used in a variety of ways. At the moment I am still trying to get the mouse to stop drawing the slingshot from another disc once it’s no longer selected. I will be looking at applying a force once I’ve gotten that far so I will post more on that then. Thanks for your interest and please let me know if you come across anything.
So here is what I have at the moment, it’s a very basic setup right now.
What still ends up happening is that if the mouse button is held down and the cursor is moved over more than one actor then it will grab all those other actors. I’m not 100% sure how to disable the activity of other actors when one has been selected at this point either.
The problem I’m having is that it does not fire in the exact opposite direction each time and can often go off at an angle. I’m just not sure how to represent this in the blueprint, you can see I have a Get Direction Vector which I use to identify where the impulse should come from but I am not sure exactly how to use all the functions in this blueprint.
Also I had originally incorporated aspects of another blueprint (link below) which is where I based this one from but it always sent the actors in the same direction but I thought it may help you with yours.
I think what I would do in this situation is store off the active ball in the player blueprint when a ball has the cursor over it.
So, make a variable in the player character of the type that the ball blueprint is, and then in Begin Cursor Over, get the player character and check this variable, using the IsValid node. If this returns false, then you have not stored off a ball, so you can store it off, and if it returns true, you already have an active ball, so don’t do anything further.
Then, when the ball is fired, you can go back into the player blueprint and set the ‘ball’ variable to empty. I think this should work for your situation!
At the moment I have only a PlayerController blueprint and the camera viewport acts as the PlayerCharacter in this sense, however do you mean to say that I need to make a separate blueprint for a PlayerCharacter in this instance as well?
As well how would I go about storing an active ball? I expect I would use an integer to set the maximum number held as 1 but I’m not entirely sure how to tell the cursor to stop grabbing other actors this way.
Sorry for the noviceness, I do appreciate all your help
Hello, StomachBug.
I saw your update about trying to do this on a 3D Plane, and guess what, I’m trying to do something similar, but I’m currently at loss. If you would kindly share the Blueprint for the 3D Slingshot, I’d appreciate it a lot.