I was following along with this tutorial here in order to have my enemy AI catch a player.
However, at 13:13 in the video, you can see that the enemy, when it has caught the player, does the animation montage for a fraction of a second, then plays the full animation montage. A comment on that video better sums up what could potentially be happening:
“Hey Matt, if you notice on your video 13:13 when the Anim montage is triggered for the first time it plays for fraction of seconds and stops and triggers the Anim montage again. This is because we have called the Anim montage twice (First when it flows from Catch player event and then second time is from rotation loop event). I’m figuring a way for this to play only once.”
Down below are blueprint screenshots of what I currently have:
Start of CatchPlayer event that will make the player’s rotation lerp to the enemy:
So the only location for the PlayMontage node is after the DoOnce, right? I see in that comment that it is also located inside the “RotationLoop” on the BP Parasite AI. We need to know what that looks like!
Yes, the only location for the Animation Montage node is after the DoOnce node. For the RotationLoop custom event start point, in the very first picture, it’ll be the highest node in the middle and it just connects into the first branch node, which continues on with the other blueprint code I’ve provided. It was sort of strange how he did it in the tutorial video but I assume it’s just for looping purposes.
AH! Sorry, I missed that. I dream of nodes in my sleep, sometimes I miss the forest for the trees.
So I notice that on your doOnce node you have that sequence node, and after the 0.5s delay it resets the DoOnce. Maybe put the Set ShouldLoop==False before the delay and raise the delay to make sure the looping fully stops before resetting?
It’s all good, I wish I could dream of nodes but I’m still a bit new to Unreal Engine!
So I moved the Set ShouldLoop==False node before the delay and bumped the delay up from 0.5 to 1. While that does fix the issue of the animation montage playing twice, it no longer moves my player’s rotation towards the enemy that catches me, and that’s sort of where I’m stumped since changing one thing seems to affect another.
I’ve been wondering how to possibly make it into two different events so they don’t affect each other like described above, but I’m unsure how to go about it.
Unfortunately the player rotation towards the enemy still does not work. Once the player is caught, it rotates the player for maybe a quarter of a second then it no longer rotates, so maybe the loop is prematurely stopping for some reason? I believe and hope I set it up correctly, so here’s my updated code per your recommendations:
The BP_FirstPersonCharacter2 blueprint now has a custom event named ParasiteCatchPlayer that has an input of a ParasiteAI object reference, as we need to know which specific Parasite to rotate towards as there is a possibility of being more than one in the level at a time. The nodes have been moved here and updated as shown:
Using the RInterpTo node means these need to be on TICK actually. The best way to do this would be to highlight all of this code minus the event “Parasite Catch Player” and collapse to function. Then promote the input parasite to a variable, and have setting that variable be the only thing your “ParasiteCatchPlayer” does.
Now, on tick, you’ll have an “IsValid?” Macro check (NOT the green function, the gray one). GET your parasite variable and off of the “IsValid-True” You’ll put the rotation function you just made, and then move on to any other tick code. If it Is NOT Valid, do not do the rotation code, and simply bypass the function and move onto any other tick code. That should do it, I completely overlooked the RInterpTo node needing tick to work.
That was the reason they used a loop, because everyone seems to think that tick is evil or something. Checking that bool is going to be less overhead than the loop that was made as their workaround.
Give it a shot and let us know if you need any more assistance!