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"

Issues with Activating Combat Mode with Line-Tracing

So, I've been working on a system that activates "combat mode", whenever an enemy is within 800 units(?) of the player, and when they are an interface is activated to the enemy blueprint, having a "soft-lock-on" cone above their head. However, I am running this with event tick and I'm not entirely sure how else to run this. Also, I'm having issues with it constantly doing its thing, once it is in combat mode. Below is my blueprint and any help would be greatly appreciated! Also critiques would be great as well!

This is essentially supposed to be like the Kingdom Hearts combat system, where once you enter a certain distance of the enemy, the HUD changes color and new music begins playing. That is essentially what I am trying to go for at least.

alt text CombatEnemyDistance = 800 MinDistanceToCombat = 0

alt text

alt text

Product Version: UE 4.19
Tags:
more ▼

asked May 05 '18 at 09:45 PM in Blueprint Scripting

avatar image

Dylanrockin
1 3 8 12

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

You shouldn't do this:

![alt text

because you're accessing a variable that technically doesn't exist, because it comes from what is executed after the branch. Move the cast to before the branch, and you'll be fine.

Not sure if that'll fix your issue, but if it doesn't let me know!

help.png (82.3 kB)
more ▼

answered May 05 '18 at 09:53 PM

avatar image

goncasmage
897 12 14 25

avatar image Dylanrockin May 05 '18 at 10:47 PM

That certainly got it to work, however I am now having an issue where the Target Visual appears above both enemies' heads. It should only appear over one enemy's head and not multiple. Do you know what I should change in this to keep it from doing that? Here is my updated BPs:

Also, I realized that if literally any actor or static mesh interrupts the line trace, then it will set combat mode to false. Really annoying, and I'm not sure what to do to circumvent that from happening.

https://i.gyazo.com/654a45aa6d8c3a48c54fec1ba3fe37e7.png https://i.gyazo.com/d914bb07d6a43b94ade5c7fa062389d2.png https://i.gyazo.com/999fef311330c610ee18cdb823fd0611.png https://i.gyazo.com/2146f462c669ebdf385a75f62559894e.png

avatar image goncasmage May 05 '18 at 11:06 PM

You can solve the LineTrace issue by using a MultiLineTraceForObjects, instead of a normal LineTraceForObjects. It will return a vector of hits, instead of just one!

Regarding your issue, when is the CombatModeInitializer function called?

avatar image Dylanrockin May 05 '18 at 11:38 PM

I just tried using the MultiLineTrace and it turns out I cannot break hit result with it, and I'm not sure what other option I have to use, in order to check if it hit an actor.

Edit: I actually just ended up setting the branch condition before distance from player check to use both true and false, because really it doesn't matter, since this is only checking if the enemies are within a certain radius of you.

avatar image goncasmage May 06 '18 at 08:55 AM

You can break you MultiLineTrace like this, you have to use a for each loop:

alt text

help.png (94.5 kB)
avatar image Dylanrockin May 05 '18 at 11:14 PM

MultiLineTraceForObjects will ignore obstacles in the way? Hm, I may give that a shot. The CombatModeInitializer is called on EventTick:

https://i.gyazo.com/f7c8cb75a9d05733b0702f930caa6c72.png

Not sure if this is where it should go, but I am still fairly new at where the most efficient places to put functions like this should be.

avatar image goncasmage May 06 '18 at 08:58 AM

Well, my thoughts are, you you're calling the Combat Initializer on Tick, it will probably activate only one enemies target visual at once, but because it's being done on tick, it'll actually do it for all available enemies in a few frames (so there is basically no difference between that and setting all the target visuals visible at once). You should probably keep a local variable in your character that tells you whether any enemy already has a target visual visible, and if it does, don't activate any of the other target visuals ;)

avatar image Dylanrockin May 06 '18 at 05:01 PM

The thing is I thought about doing something like that, but I wasn't sure how to go about doing it, since it takes in an array of dudes and I'm not sure how to tell the game "hey, BP_Example_Enemy_2 has an activated cone over his head, so you, BP_Example_Enemy_1, cannot have one."

avatar image goncasmage May 06 '18 at 05:44 PM

Keep a boolean in your player character that will be true once an enemy detects/is detected by the player. Whenever that boolean is true, no other enemy can detect/be detected by the player (which is something you do in that same blueprint).

avatar image Dylanrockin May 06 '18 at 07:28 PM

I am starting to get a little confused. Then again I have been banging my head against a wall with this one for several hours, so that may be why XD I am struggling with where specifically I'd put it.

avatar image goncasmage May 06 '18 at 07:30 PM

In which blueprint is the logic you just showed in your screenshots?

avatar image Dylanrockin May 06 '18 at 07:39 PM

In third-person-character I have everything running on event tick, here: https://i.gyazo.com/34849f4e766a30bc8e3c064dc831defe.png

And Soft Lock On is part of Third-Person Character, here:

https://i.gyazo.com/06f0b2262aa4ee426d9e631c826c0c8d.png https://i.gyazo.com/e269e9311a1b0e25c66a87595c7feff8.png https://i.gyazo.com/b0d668ad046e027b0455f42831d2deb4.png

And within the Enemy Blueprint there are several events for different situations, such as determining combat mode, and the hard-lock on, which turns the soft-lock on gold instead of arrow-blue:

https://i.gyazo.com/5c1be77b05c223ab3d9709ae3652b16e.png https://i.gyazo.com/3735e20f942892effee1ea7271a46baf.png

avatar image goncasmage May 06 '18 at 08:39 PM

You have to use your TargetSoftLocked boolean to stop an enemy from being soft locked. Try to think about how the code is gonna flow, what variables are gonna be changed to what (specifically the TargetSoftLocked bollean). Your setup doesn't work, because if an enemy is already locked on, it will simply say that no enemy is locked on and execute the code regardless:

alt text

What should be happening is, if the boolean is true, don't do anything except for checking if the enemy that was locked on is no longer locked on. When it stops being locked on, then you set the boolean to false.

If this logic confuses you, maybe you should take a step back, or maybe look at a couple tutorials.

Focus on doing one thing at a time. Do one part of your system, then another one, then another one, because if you don't, when you test it, it doesn't work and you don't know why, and then you have to look at a bunch of stuff that you did and you don't know what works and what doesn't. So be careful with that, especially if you aren't comfortable making these kinds of systems.

I'm not telling you to stop! I'm telling you to take a step back and do things one at a time :)

Cheers!

help.png (57.7 kB)
avatar image Dylanrockin May 06 '18 at 09:36 PM

I believe I got it working now! There are some other issues in regards to the hard-lock on system, but that should be fairly easy to rectify compared to this. But, if you see anything wrong with this setup in the screenshot, let me know! Otherwise it only sets the visibility for the cone once and that's all I need. But, who knows, I may come across something dumb along the way.

https://i.gyazo.com/d70f91b3868d11db4d393fd90ecad178.png

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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