I want to make a force shield that will be able to block enemies projectiles and pass through player projectiles.
I might use some triggers to turn on/off shield or change collision rules, but it seems to be far from perfect implementation.
Will be very appreciative of any ideas.
If you turn your shield on/off, it will affect every other projectile at the same time. I would suggest changing the collision settings of the projectile. For Example:
-
Have your proyectile with a collision component slightly bigger that will only overlap waiting for a valid actor:
-
Create a new collision channel and set your projectile collision Object Type to that channel and the channel to block ignoring everything else:
Be default your shield class should also have that channel set to block.
- Finally, you have to find a way to know if the projectile is moving towards the shield from behind or not. To do this you can use ProjectileVelocity.Normalize() · ShieldForwardVector → If > 0, Projectile will hit from behind.
Result:
Using the same logic you can then have some fun and block comparing attributes:
Same with traces, but the checks are done on the actor that traces:
Thanks a lot, you have put in a lot of effort to show how this works.
Hm, tried to do the same but it doesn’t work, can’t understand why.
Here are my ball collision settings
Here are the ball’s collision settings
And shield settings
Where is the mistake?
Also, does ordering of the ball and sphere collision matter or not?
For no reason, it works now. It’s a pretty strange
UPD But sometimes a ball pass through the wrong side of the shield
Depending on the expected max speed of the ball, youll need to adjust the collision sphere so that its big enough to touch the other actor with enough margin of error. Try playing with that.
Did you manage to fix the other issues you typed above?
Overall It works pretty strangely. I reproduced this logic to my projectile and it doesn’t work at all, can’t find the reason why the same works on “balls” but doesn’t work on my projectiles.
What I’m trying to make - the projectile flies through the “shield” and then hits an enemy behind. Also, I don’t need any physics and when it hits the enemy or wrong side of the shield it must be destroyed.
Before I made such simple logic to apply damage in my projectile
And here is what I have
Well, how are you moving them and how is their collision set up ( settings and component ) ?
It doesn’t matter. Better to ask you about general stuff to know how collision layers are working.
For example, I have a projectile that must ignore the first object, overlap with the second, and be blocked by third
So, how to set up collision rules for projectile and for all 3 types of objects?
- Am I right to do such in the projectile?
- What must be in settings for each object?
- Am I right that this setting determines what type of object a component should be assigned to when checking for collisions?
Yes. Your projectile can be any object type, but the walls have to be assigned Objectes1 , 2, 3 profiles for this scenario to work.
Object Type:
- Projectile = anything (physics body in my case)
- Wall_1 = Object1
- Wall_2 = Object2
- Wall_3 = Object3
All the Object# can have PhysicsBody (the type of the projectile) to Block and it will work just fine.
Got a little confused with the wording of the question, but think of the Object Type as a profile that other actors will see when colliding with it and the Collision Responses what the actor will do when it sees that profile on the other actor:
UE had a nice table in their documentation site but can’t find it. So found this with a quick search:
Source: Collision Filtering - Unreal Engine
My memory is BAD… so I need an easier more numbers way to remember, think of it as selecting lowest out of Row * Col:
Hope I passed your test…
Better yes: did this passes Host’s test?
Again, thanks a lot
Finally, I’ve found the reason why the block on projectile and barrier didn’t work at all.
The reason was pretty simple but unobvious - if a projectile mesh is not a root - collision settings won’t work properly
I guess it depends how you are moving the projectile.
I’m moving it by using the projectile movement component