How can I have the player "charge" a projectile by clicking and dragging the mouse?

As the title says, I’m trying to implement an Angry Birds type of click and pull mechanic to affect the speed of the player’s projectile. Is there a way to do that within blueprints?

The logic you need to use is “OnClickEnter” record the click location and “OnClickExit” get the new mouse location. The displacement between the two points can be used to calculate both the direction and the magnitude/multiplier for your force.

Thanks for the quick reply! I’ll try this out and get back to you.

How are you referencing the “Sphere” component as the target in the “Add Force” function? When I try to plug in my target, an error pops up. “Static Mesh Component Reference is not compatible with Character Reference”. Thanks again for the help.

There are two ways you can do it. It comes down to preference and is ultimately the same thing.

I added a sphere component to my blueprint. I selected the component so it was highlighted. I right click on the node window view and typed add force and it listed the addforce(sphere component) because my context is focused on that component.

Alternatively you can drag the component from your component window (left of screen) and do the get option (giving you a node of the component) and then you can drag from the pin and access all functions (and properties) relevant to that component instance.

I made a gif to make it easier.

59351-bptest.gif

Ok. I got my mesh referenced to the Add Force function. Unfortunately it isn’t moving when I use the mouse to pull back and release. I can see in the graph editor that my functions are hooked up correctly and the connections between them light up with the right inputs. In the Add Force function, I don’t see the Accel Change node that is present in the Add Force function in your screenshot. Additionally, my Get Mouse X and Y have targets (self), while I see yours doesn’t. Is there something I’m missing?

It shouldn’t be a big problem. If you click the add force node you added there should be a drop down arrow at the bottom which extends the node with the additional option.

As for the GetFunctions it is dependant on the context, the function nodes you chose were dependant on the component you selected (the context).
When you right click in the node window there is an option in the top right to enable or disable context. Try disabling the context and adding the Get Mouse X and Y nodes (you might see two identically listed functions) and see if there is a difference. Aside from that it could be the type of blueprint you are using, my example was on an actor but you might be doing it on a pawn which could have some different rules.

edit Actually both of these issues are not problems. The differences are due to your engine version.

I’m glad I at least did that right. However, the object still doesn’t get move when I release the mouse. I have tried it simulating physics and not simulating physics, but to no avail. I should clarify my project a bit more. I am using a character to move around a level and be able to throw an object that spawns in on the character. I basically want to spawn the object near the player (I’ve got that figured out), hold it in place and use the mouse to drag and determine how far the character will throw the object, then release the mouse and throw the object.

I also upgraded my project to 4.9.

It is a 2d game right? (I thought it was due to the angry bird thing). There are a few things that can prevent it moving.

Reasons why it isn’t moving include:

1)static mesh object (projectile) is attached to something preventing it from moving,

2)The force/movement/location keep getting overwritten; maybe by your character trying to make it follow your player.

3)The force isn’t enough of a displacement to see the movement you want (try cranking the force up to the 1000s). Remember gravity and friction still work unless you disabled it.

There are things you can fix and alternative ways of doing the feature. I will assist where I can but I don’t know the full set up to spot the problem.

You also might want to consider using the projectile movement actor component in your project in future, it sounds like it is more what you want.

Yes, this is a 2D game. I was using projectile movement before, but my project head wanted me to use a scalable power throwing mechanic. I’m hoping there is a way to modify the velocity within the projectile movement from the blueprint editor. Do you know offhand how to do that?

I think the main reason I wasn’t able to get the Add Force function to work was because I was trying to use it with a Skeletal Mesh, rather than a primitive parented to the Player blueprint.

Okay yeah that would make sense. If you do it on a skeletal mesh you will need to specify the main bone to apply force to.

Yes you can modify the projectile component velocity during runtime with blueprints. If the spawn node is what I think it is you can drag a pin of the spawn node and access that instances projectile component, where you can plug in the velocity you want based on your firing conditions.