x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: UE 4.9
Tags:
more ▼

asked Sep 19 '15 at 07:59 PM in Blueprint Scripting

avatar image

Chimps
48 4 8 10

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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.

Image showing a basic set up for doing the firing

more ▼

answered Sep 19 '15 at 08:41 PM

avatar image

Jakey113G
543 17 79 89

avatar image Chimps Sep 19 '15 at 09:12 PM

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

avatar image Chimps Sep 19 '15 at 09:26 PM

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.

avatar image Jakey113G Sep 19 '15 at 09:57 PM

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.

avatar image Chimps Sep 19 '15 at 10:28 PM

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? alt text

bp_pullnrelease.png (321.0 kB)
avatar image Jakey113G Sep 19 '15 at 10:53 PM

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.

avatar image Jakey113G Sep 19 '15 at 10:11 PM

I made a gif to make it easier. Gif1

bptest.gif (539.2 kB)
avatar image Chimps Sep 19 '15 at 11:09 PM

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.

avatar image Jakey113G Sep 19 '15 at 11:36 PM

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.

avatar image Chimps Sep 20 '15 at 12:18 AM

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.

avatar image Jakey113G Sep 20 '15 at 12:25 AM

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.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question