Destroy projectile When the Projectile itself hits something/anything?

Ok this is Kind of a 2 part-er.

First off Merry Xmas everyone and or happy holidays! or Whatever saying you subscribe t =)

Part 1: Like the title asks, I cant get a Custom Sphere that i am using as a projectile to work. I just want the projectile to disappear when it hits either a static mesh, character, actor, anything. I have tried using on hit event but the hit actor needs to be specified, does that meant i have to put a hit event for EVERY possible hit interaction? I have tried adding a hit event on each mesh in the game, and still it just bounces around…

Part 2 (not as important): How do I prevent the projectile from harming the person shooting it in the event the “instigator” is hit with the projectile?

Thanks!

Hi, first off you need to add a ProjectileMovementComponent to your projectile actor. Then from the ProjectileMovementComponent use the OnProjectileBounce event which will fire when the projectile hits something.

As for Part 2, you can use IgnoreActorWhenMoving on the component that you use for collision in the projectile.

2 Likes

Thank you so much!!! It only worked with an “Event Hit” but you got me looking in the right direction! Thanks!

@MindfieldsTech

Projectiles are Collision, the static mesh is the visual element and has zero collision. Projectile Movement Component (PMC) handles the physics and math.

To prevent the projectile from colliding with the character I use custom object types for the Pawn Capsule, and the Projectile.

  • Change the pawns capsule component collision object type to “Pawn Capsule”. Have it ignore projectiles.
  • Change the projectiles collision object type to “Projectile” … ignore “Pawn Capsule”.

https://docs.unrealengine.com/en-US/…ype/index.html

This approach allows for skeletal mesh hits. Arm, head, leg, torso, hand etc.

**Spawning the projectile … **

**Projectile Hit Detection . . . **

Here we check for a blocking hit, if true → destroy Actor (self … the projectile actor) . Next we place a debug point to show the collision point, then cast against the hit actor. If the cast fails, it’s not a player pawn.

Thanks! I was going to venture into doing different damage per skeletal hit! I appreciate this!!

A good step would be to add physical materials (arm, leg, torso, head etc) to the phys asset. Then get the physical material hit in the hit result. It’s a lot better than doing per pone switch checks for damage calc. 5-8 vs 26

Need more info hmu.

I remember doing it once before, but its a bit fuzzy in my memory, I don’t remember how to setup the physics asset. I remember how to adjust the damage output in the physicals material. If you have time I would appreciate a refresher =)

I had literally just setup the exact way you mentioned NOT TO, temporarily, to test using the bone hit and branches and adjusting the base damage on the apply damage lol

This is what I remember doing so far.

Now i am adding the individual Physical Materials to each bone capsule.

I am just uncertain how to script the hit result physical material hit to the base apply damage base damage…

also What I noticed is now my characters after making it a “PawnCapsule”, when they bump into one another, they kinda knock each other around. Like if i run into another player, they go flying into the air, or get bump backwards…

@MindfieldsTech

First off you need to verify your pawns collision settings. I mirrored the default settings the TPP character uses.

For the phys asset …

Calculating dmg …

Hit Physical Material -> to String -> Switch on String.
Each element in the switch needs to match a physical material.

*Calculations are done in the projectile class.

My preference is to pass the phys material and bone to a function which will calc and return a float.

If you have different weapons with varying dmg models then you’ll need to pass a reference of the weapon into your calc function.

Typically weapons are spawned actors that are attached to the pawn. All specs/dmg models etc should be coded in the weapon class itself. Thus take the reference for your cast pawn -> get your weapon -> pass to func.

Thank you so much for all that!

I am a bit confused which do I link where? Do I have to name match to the bones? Why am i also connecting the bones name to the function?

I am guessing I am using either the function or the Switch on string?

Do the physical material names be named exactly as the switch on string outputs?

When I pull off the Phys Material to the function i get None in a print string.
When I pull off the Hit component> get material >get physical material> to the function- I get “DefaultPhysicalMaterial”…

I have this so far:

is this correct for the mesh? I also added the physic â– â– â– â– â–  to the mesh, but the hit result always shows :DefaultPhysMaterial

Projectile Collision -> “Return Material On Move” … it’s in the extended collision settings below “Use CCD”.

*“If true, component sweeps will return the material in their hit result”

Character Mesh Collision:

https://i.imgur.com/AXg55Dl.jpg

I do not have a physical material applied to the skeletal mesh. My gut is telling me that there shouldn’t be one. Only the physics asset should have them applied.

**- - - - - - - - - - **

Physical Material Names / Switch : For each material you add to the physics asset you must add the name to the switch.
e.g. If you have stomach material applied and it isn’t in the switch, then 0.00 will be the damage calculated.


Damage Calculation (func)
I pass bone to the function for special purposes (game play relevant). When players take damage to their weapon arm/hand it applies a recoil, sway, spread penalty when they shoot. Hitting legs will apply a movement speed penalty. Knowing what exact bone has an impact on the severity of the penalty on other player anim states etc.

My setup is a bit complex you don’t have to pass bone if it isn’t needed. Here’s a simple break down.

https://i.imgur.com/37zgsUN.jpg

https://imgur.com/GjLHfo8.jpg

** open in new tab for higher rez*


Demo Vid

https://www…com/watch?v=tC7SBY25z-o

Thank you so much for your patience in clarifying things for me! I really hope you don’t mind, but I have a few more questions…

  1. How are you grabbing the projectile owner object variable? and where is the player name coming from? I dont get that when I pull…
  2. When I set the player hit object var I also cannot pull and get a “Player Name”. How and where is that being passed?
  3. For the life of me, I cant figure out what to attach to “instigator” on initial “SpawnActor”??

Projectile Owner is a custom variable in the projectile class. I set it when I spawn the projectile. I pass a character reference to it.

Player Name is a custom var in the character class I use for debugging. Just a random from array that’s set in the construction graph.

https://imgur.com/bKs7bY8.jpg

My set up is that the weapon class is the one that spawns the projectile (holds all firing logic). On Begin Play (weapons class) I create a reference to my character class. This reference is what’s passed to the projectile on spawn and used as instigator/owner.

https://imgur.com/1LJdmyE.jpg

is this sufficient for setting projectile owner in the projectile BP?

I GOT IT WORKING!!!

I am an idiot!!!

I accidentally had the ENTIRE projectile firing script in 2 places. I Was triggering it with an animNotify in the ABP and I had it firing in the Character Bleprint.

The one in the animNotify Was running PRIOR to other programming additions, but was overriding ANYTHING I was doing!

THAKS SO MUCH FOR YOUR HELP!! I GOT IT WORKING PERFECTLY!!!

Excellent.

FYI the way you’re getting the player reference wont work unless you’re spawning the projectile from the character class. In my demo I’m spawning the projectile from the weapon class. So I need to have a reference for my character in the weapon class.

My weapons are not parts of the character itself. They are spawned and attached. When I spawn them I set its char ref var with self.

https://imgur.com/jeVfOJZ.jpg

Now my weapon has a direct reference to my character class. I can use this var to pass reference to the projectile.

I can record a video of the process tomorrow if you’d like.

Yes The updated version of my script is now Running on the CharacterBP. In The Character Blueprint I am Spawning the Projectile on button “fire”. There I am passing the character variables through the “spawnactor” into the projectile BP.

Yes Please! I am learning so much and I appreciate it! Any Reference images or videos will be greatly useful to me! Thanks so much!