Download

[Paper2D] Help with Basic Attack

Hey guys

I’ve hit a wall with Blueprints that make me realize how not intuitive this scripting language can be some times.

I want to make a basic attack for my archer sprite, and the animation is there.
But I need to fire the arrow from my archer on Frame 4 of my 6 frame long animation. To avoid collision issues I should spawn this actor (A Blueprint called Arrow) some pixels away from the origin so that it won’t collide with the archer and never spawn as it’s destroyed on impact with an object.

In normal code I would most likely just have made a while loop that checks whether the notebook’s flipbook was at the desired frame, and when it was spawn the actor with the right rotation (as you can look left and right), and enough pixels away from the character, as well as adding forward momentum in that direction. But translating that to Blueprint have proven tedious and incomprehensible. While loops are just not very intuitive in Blueprints.

This is how I Start it:

2d453bf8b1e19c5388db2887d2d028c82883ba4e.jpeg

The bIsFiring boolean is used to prevent the player from moving while firing which seems to work fine.
But with this, the firing animation doesn’t even trigger but just makes the character freeze for a split second and continuing the idle animation.

The animation that should play:

So I am sort of stuck, any help?

Hey!

There are some limitations with flipbooks and frames. Unfortunately we still don’t have something that fires on a specific frame . What you experiencing is nothing!Wait until you need to sync a SFX to a flipbook frame :stuck_out_tongue:
The easiest way to do what you want is to divide your animation into 2 animations.The first one will finish at the exact frame that you want your arrow to spawn.Then add a scene component to your blueprint. The code will be like this:

Play animation_1—set not looping----On animation end----spawn arrow from scene component---- play animation_2 (and if you want to go to idle after that)-- On animation end---- set looping----set animation Idle-- Play from start.

Note: You need to create some sort of logic for the"on end animation to work". save a variable with a name on every animation when it first fires and then

On animation end --is name animation _1? if yes play animation_2. No? —Is name animation_2? If yes then go to the idle logic.

Hope i helped!

I have sort of made it work now. At least the arrows spawn now <_<
But there is still really weird behaviour!

You see that?

  • The arrows spawn on the right side regardless of rotation of the archer
  • The arrows despawn if the character jumps which means no arrows in mid-air either
  • The arrows have no momentum

Playing the attack animation:



The Arrow Blueprint:

Forget about using physics.Just use a projectile for your arrow. Depending where you face reverse the projectiles initial projection.And use a scene component.If you flip the actual capsule then the scene (because it is a child of the capsule) will rotate left and right depending where you are facing.That will save you a lot of trouble.

So using a Scene Component and then use a Projectile Movement Component…? I’ve never done this before so I am sort of fumbling through the dark.

No, The arrow must be a different BP with a projectile that has the arrow as a child.From your archer you will spawn from the scene component the Projectile BP.In that BP on Event begin play you will see if the player is facing left or right and you will apply initial force as x or -x so the arrow will fly in the right direction.
EDIT: and you have to flip the arrow as well :wink:

A little bit confused by what you say.

I have to add a ProjectileMovement component to the Arrow (and the arrow sprite can’t be a child of the ProjectileMovement component as it’s not a scene component) and then I have to add the necessary force in the MyCharacter blueprint which is the instigator of the firing action?

:confused:

Create an empty actor BP. Add a projectile component,add your arrow sprite.Name that BP “ARROW” (lol)

Save the player movement (1= right -1=left) to a variable.
Add a scene component in your main character. On animation end(shoot)–get scene—get world location—spawn actor of class “arrow”.

Arrow Bp:
On begin play --get player–cast to player–get that variable. is left give the appropriate initial velocity and reverse the arrow and vice versa.

If you ask me again after this i will have to come and script it my self! :stuck_out_tongue:
Cheers

I got it working now so that the arrow spawns on the right side with the right rotation now.
But no forward momentum.

Also this, what even?

See? With a little effort everything is possible! It would be impossible for me to explain everything in detail. I was just giving you a overview on how to approach your problem.Wish i had someone to tell me all that 6 months ago when i solved this problem, and mind you half of the stuff i am describing here were either missing or broken. But fear not! We need more paper2d users out there so let me see how i can further assist you.

Just do what the pictures show you and you will be just fine. As you can see you do not need to have any “code” inside the arrow BP. You can do everything from the player BP.bd33aefeeefbe683d40be967889ca5f445df1654.pnga945cbe80b59a75d4891b5d8bd024e155346046c.png

Okay, I tried to do what you said, but the result is…weird.
796afae5558d8306cef972201fce9af2568be095.pnga27c950fffd04c52b0930031d8eb5b3d82785d07.png
ed4714bb9d0b479be2e836a9f79106c689b4f3e7.jpegba28a579dd9520fe6b84e2595826c35e94cf4f55.jpeg

You get his orientation from the scene component??From the rotation???
a9ca335c70c5735fec3d654c710ce03f73004292.jpeg

This is so wrong in so many places that i do not know what to say…

Friendly piece of advice. You need to study a bit more how everything works. I told you a few posts back to get his orientation by simply saving a variable from the Axis movement.Or if you are using keyboard only then by each key.

cb668c9d1d221d3dfaac2198170150dfd3854dc9.png

1-RIGHT -1=LEFT 0= IDLE

Being condescending is not helpful at all. I come here for help because obviously Blueprints are giving me trouble. I appreciate your help, but please drop the condescension. I don’t need that. So spare me the attitude, you are a spotlight member, you should know better.

I already have programming experience with Java, C# and to a small extent C++. I am trying to utilize Blueprints because C++ is very hard to learn for me and I honestly don’t have the time to learn it right now, or I would have gone with that.
I changed it to just take the input axis as the variable to determine rotation and it didn’t help jack ****. It broke it instead (Yes I am ****** by that attitude).

It now fires a miniature arrow (not the 8x scale it had before), it still falls to the ground instantly and now the animation gets stuck in an infinite loop.

f679425280729a1a66f17b21750c0c15c0f525b9.jpegbf11e8651de86f0bc84a3254b5993b7a93b7f40d.jpeg

I have no attitude whatsoever. I have stopped working to help a fellow Unreal engine user.I am trying to give you knowledge that few people would share. 5 minutes of me explaining something to you might be a month of hard work for me.You are a programmer,you know how these things work.
Having said that i insist that you need to take it slow and start from the basics because you clearly lack some fundamental knowledge of how things work with blueprints and Unreal.This is not to make you feel bad or insult you!It is just a fact.How do you expect to make something like an archer if you don’t know how scene components work,projectiles,physics in paper2d and the limitations of the animation system?And even if you knew all that you would still have to mix them creatively to achieve the desired result.

Make no mistake,what you are trying to achieve is pretty complex especially when you start messing around with collisions and enemy A.I . So relax,sleep over all the information i gave you and tomorrow morning with a clear head try to make it work!

Cheers.

You use pictures such as:

c15ff5ae06.jpg

And sentences like:

Do you think I am enjoying coming to ask for help instead of being able to figure this out myself?
You are coming off as rude with these comments, as if I am just a moron.

Seirously, don’t do that. I’ve read over what you wrote several times and I don’t get it. Your way of “explaining” things is very lackluster, assuming I know everything about Blueprints.
And when it’s clear I don’t, instead of trying to bring your explanation down a few levels so I could maybe learn from it and figure out things myself, you just leave me more frustrated than when I started. I am pretty positive I did everything you explained to me, but it still doesn’t work. If I am not doing what you asked me to do, I have to correct it somehow, rather than just take more **** for doing it wrong.

Again, I appreciate your help but I don’t appreciate all the snide remarks of how I don’t get it, or how I should give up and start from “scratch” whatever that means, as there is no bottom to start from.

I guess my sense of humor doesn’t come across very well in writing.

There are 2 ways to approach something as hard as game development. One is to get angry which is the first reaction of any normal human being (myself included) and the other is to master your feelings and try to stay positive and energetic. I prefer to go with the second option and thus my comment"see?With a little effort everything is possible!" was in fact a motivational phrase.

In general you should know that people are always willing to help as long as you dont drag them down with questions that they think that you already know. Let me explain. I consider myself at the absolute bottom of the game development food chain. I probably have the IQ of a caveman compared to any one of the Devs here. Now if i go and ask for help, for lets say an algorithm that constrains physics objects someone will try to help me for sure. But if by post no3 he realizes that i don’t even understand how algorithms work in the engine he will probably get annoyed because his intent was to guide me to find the solution and not to explain to me how math works.

See where i am heading here? I never had/have/will ever have any intention to insult anyone.It is just not me. What i am just saying is that it is impossible for someone to explain 5 different things that are required for you to achieve the result you want!

Just break them down into answerhub questions and i will gladly try to explain with what little knowledge i have. Then when you have mastered every single aspect of the required things then you can combine them using my above posts to finally have the archer you deserve. :slight_smile:

Just for your information I achieved the desired effect.
Only problem now is odd physics when the arrow has left the bow.

What do you mean by odd physics? The fact that it is going straight?

Did you watch the video until the end?
If I step on those arrows I go all over the place.

Doesn’t matter, made them destroy on impact.

Do you have them as physics actors? No need for physics inside a projectile.If yes turn them off. Or maybe you have “can step on” to off. Anyway good luck with your game! Happy that you made it work.