Charge forward attack

I have been trying to make an attack where my enemy charges forward and if it hits anything damageable. It will deal a specific amount of damage. However, I have been having trouble getting it to move to the desired location and direction, as well set off the damage event on hit. I want the ai to charge forward about 15 meters. Attached below is a photo of the code im using. I apologize if the code is messy if gone through many different iterations trying to make it work.


Here is also a photo of the actors collision:

I’m not sure if event hit isnt working bc teleport is set for the set actor location but if I don’t set teleport to true. Then the actor does a phasing in and out thing and randomly spawns in a completely different location.

Hey @ItsssYucky!

So Teleporting prevents the movement from altering the physics state of an actor. It shouldn’t cause any sort of phasing in and out.

One issue I’m seeing is your Lerp. You’re using the current location of your actor each time, but that value is changing as you move. So you need to SET the A to keep it from changing. Set that vector as a variable before the timeline, and use it for the A on the Lerp. Maybe name it “ChargeStartingLocation” or something. :slight_smile:

That’s the main thing I’m seeing. Give that a shot and let us know how it goes!

2 Likes

Thank you so much Mind-Brain. I am not home right now but when I get back I’ll be sure to make those changes and let you know. Once again thank you so much.

Im noticing the problem persists where the actor is not charging toward the player. Even tho I set it to just get the actor forward vector it is still not going directly forward. Do you see any reason here why that might be occuring? Thank you for the help.

Maybe change it to “GetActorForward”, but if the arrow is perfectly the front then it shouldn’t matter.

We’ll really probably need eyes on this- make sure the arrow is not hidden in game, and try to get us some video if you can! The WAY that it isn’t going directly forward will matter here. We’ll worry about the collision after the movement being set up! One thing at a time, better to focus each problem individually than to spread your efforts! :slight_smile:

Thank you for all the help and sorry for the late reply. I’ve been building a pc so haven’t been checking. I did try to change it to get actor forward vector and it didn’t really change anything. When I get the chance to check it I will let you know which wrong direction it’s moving in. That’ll probably have to be tomorrow at this point. Once again, thank you for all of the help.

1 Like

As far as I can tell when he is travelling in the x negative direction he moves towards in the wrong direction towards his right. When he moves in the x positive direction it is towards his left. Depending on where the player/platforms are in front of him is he will still move forward sometimes but it will always be offset by some amount to his left or right depending on the corresponding x direction.

Edit: This is still the best pattern i can find but it really isnt predictable. I am using a draw debug sphere. To see if it is moving in the specified direction and it always moves to it perfectly.


Is it possible its bc im clearing focus just prior to running the attack?

It sounds like the mesh needs to be turned 90 degrees to match with the forward of the actor.

But it is hard to say- again, we’ll likely need eyes on this. If you could show your viewport on the actor blueprint and your relative rotation of mesh and horn we may be able to count that out. Horn is not the parent of mesh, so we can’t say for sure that they’re lined up correctly.

Sorry, this is a tad unclear. The debug sphere is going to the right place but the rhino is not?

Here is a photo of the code I changed the it to just be “get actor foward vector” instead of get forward vector of the horn. Here is the new code below:


Here are photos from the viewport


The arrow in the center is the horn and the arrows on the side are for different attacks so pls ignore those.
To be clear the rhino and the debug sphere where going to the wrong location, but it was the same wrong location.
Another problem that just started occurring is every time i run the system ue5 crashes. I have a saved version of the old code and that doesnt crash so I definitely took a step in the wrong direction.
Sorry this is so complicated.

No worries! Strange that it crashes… But one thing at a time.

If you highlight the Root Component (CollisionCylinder), does the red “X axis” arrow line up with the white “Horn” arrow? IF SO, we can rule out a rotation issue with the build and arrangement of the components. After that we have to look at the code and possibly the behavior tree?

Maybe use the move component to function (move the root component of actor, commonly the capsule component) on IA activation, set a damage function to the on overlap event

Those arrows do not come up whatsoever. When I have objects that come from the parent class I cannot use any of the other modes, like rotation, scale, and location. But the arrow component that comes with the character class, which is meant to show which direction is forward, and the horn perfectly line up. I also wonder if it is something in the behavior tree or code.

Sorry Ive never used it before so I may be doing this wrong but I am not noticing any movement with the move component to function. Here is the code below.

Usually I use the collision component like capsul component but maybe try moving a different component, you may need to disable character movement before then re enabled after

Can you post the whole function blueprint?

Going that route, you can use the “MoveTo” function, which could work. But you wouldn’t need a timeline for that, or “MoveComponentTo”. “MoveComponentTo” using the root is the same as MoveTo, the problem there is that MoveComponentTo is asking for RELATIVE position ie. relative to its parent, of which there isn’t one for RootComponent.

But you could attempt using “MoveTo” with a target destination. On the start you’d Get the target’s location, set that, set MaxWalkSpeed to something high, and then activate MoveTo, setting the MaxWalkSpeed back to normal upon a collision or if the MoveTo gives a “True” on the red output pin.

All of that aside- Everything really did look good on what you had- looking at the behaviour tree may hold some secrets. I’m thinking something to do with your “Focus”.

Yeah here is the whole blueprint:


Is there a benefit to using move component instead of set actor location? This also seems to be working but frankly I cant really tell bc every time I run the game with this enemy it crashes.
Unreal is still crashing when the actor starts moving for whatever reason. I think it has to do with when the enemy actor collides with specific platforms but I am not really sure. When the actor is not placed in the level it doesn’t crash. I do some more testing to see if it crashes even when the actor doesn’t run the function. But I don’t think it will.

Yeah I am slightly more inclined to keep using what Ive created instead of scrapping it and starting fresh but I dont really care as long as I get the attack working.
This is the focus btt in my behavior tree


It runs before a 2 second wait and then the btt that calls the charge attack.

It’s probably not liking that you’re using a Timeline with a subprocess in the update. (moveto, delay, etc, the ones with the clock on them)

I did have a thought- you say it’s always veering in a direction that’s a little off. Is it always the right side? Or is it possibly trying to go to a specific location? Like world 0 perhaps?

Im working on a top down RPG, kinda like Diablo, i was able to accomplish a dash with this, note i have an invisible collision box(Shield 1) as a location holder set on my character for blocking and a few other functions hope this will help

Aside from the move to, wouldnt the only subprocess be the delays that are firing off before the timeline. Additionally I removed the sub process from the program and unreal crashed the moment the ai collided with something. Even if I set it to teleport it is still crashing. Do you think that its possible that the reason my ai isnt working is bc its colliding with the surrounding environment? I narrowed down the function to exactly when the AI moves. In a test i did where i moved it straight up so it wouldnt colllide with anything, unreal did not crash. So im pretty sure it has something to do with collision but I can even edit the collision channel of this individual actor for some reason.

Looking back at a video I have from before it started crashing every try. It seems to go back and forth between two areas without regard for the player. Its going to the are past where the player spawns and then back to the area where it spawned. It goes back and forth between those areas and the points in those areas seem to change slightly over time. Once again tho it is really difficult to tell.

I will certainly give this a try when I get back home and let you know. Would I need a component to be 15 meters away from the actor to make this system work assuming I want the actor to move 15 meters forward?