Arrow stick into character's sword

wuyan

Member
Hello,

Please take a look at the first screenshot. The arrow will stick into the sword in the character's hand.

I hoped that through some modifications, the arrow will react differently when hit different items. For example, when it hits an iron weapon, it will rebound, and when it hits a wooden shield, it will stick into the shield. But I find a problem. When an arrow hits a GameObject in a character's hand, it will becomes a subobject of the arm, but not the GameObject. I checked Projectile.Oncollision (raycast hit? hit)。 Although the arrow only collides with the collider of the GameObject in hand, I can't get the information of this GameObject here. hit.Value.Transform.GameObject is the right arm. It makes me confused. Why? And what should I do? Thank you!

1624469933585.png
 
Last edited:
First, you'll need to make a new layer for weapons, that's pretty much the same as "default." Then you have to change sticky layers on the arrow prefab.
1624471369084.png

Also, if you want to stop "decals" (like bullet holes).

I'd give the sword a metal surface type. Then under the sword prefab, go to surface identifier (or add it), put in the metal surface type, and don't allow decals.


1624471026538.png
 
First, you'll need to make a new layer for weapons, that's pretty much the same as "default." Then you have to change sticky layers on the arrow prefab.
View attachment 6241

Also, if you want to stop "decals" (like bullet holes).

I'd give the sword a metal surface type. Then under the sword prefab, go to surface identifier (or add it), put in the metal surface type, and don't allow decals.


View attachment 6240
Hello DavidC,

Thank you! Have you tested it? I've tested that and it doesn't work.

1, I'm not sure if changing the weapon layer will cause other problems because it's the default.I don't know if the source code calls the weapon layer.One problem I can confirm is that if I change Layer, the weapon will collide with the character who take it. Although maybe this problem can be solved using UltimateCharacterLocomotion.AddIgnoredCollider, it just confirms what I said . The source code calls this weapon layer. This is one, is there any others? I don't know. Need to be familiar with the source code.

2,I just tested it again as you said. When I cancel the sword layer as sticky layers, the editor will crash when the collision occurs. And also I found that the impact layers and sticky layers of arrow don't seem to work very well. What is really effective is the shootableweapon impact layers of Bow.(Sorry,These errors are caused by my code.)

3, According to my understanding, in Projectile.Oncollision (raycast hit?) , Hit.Value.Transform.GameObject should be the weapon (sword) hit by the arrow, not the parent of the weapon the arm. The arrow should be the sub object of the weapon, not the arm's. In fact, the result of my test is that any sub object of Hand Items will be this result. not only weapons. So I guess the source code did those somewhere. I didn't find where.
 
Last edited:
Can you clarify more about the issue with sticky layers? When you say the editor crashes, do you get any errors in the console? And what doesn't seem to work about impact/sticky layers? Those should definitely be the place where you'd manage exactly this kind of behaviour.
 
Can you clarify more about the issue with sticky layers? When you say the editor crashes, do you get any errors in the console? And what doesn't seem to work about impact/sticky layers? Those should definitely be the place where you'd manage exactly this kind of behaviour.
Hi Andrew,

Thank you!:)

1,Sorry,These errors are caused by my code. I've fixed.

2,Can I add rigidbody component to wielded items, such as sword,shield?? Because the default is not.

I have found the reason for the third problem.Because in Project.Oncollision (raycast? hit), assigned the parent of the projectile to hit.value.transform.gameObject. Hit.value.transform needs to be a rigidbody. Use arrow and shield as example. If the shield is not a rigidbody, it will try up to get shield's rigidbody parent , that is the arm. So, the arrow will be a subobject of the arm.But if so, there are two problems. One is that it can't meet my needs. The other is that there is a hand joint between the arm and the shield. The animation of the hand joint makes it look like the arrow doesn't stick tightly to the shield,there is a dynamic offset.
 
Last edited:
Ok, I dived into this deeper and figured it out. So atm, sticky layers doesn't do anything at all because the collision mode is "collide." This is more for grenades that will bounce off some objects and stick to others. You could make the arrows bounce off swords, I think, by changing to "reflect", but then I think they could still trigger damage on the rebound, which might not be what you want.

The arrows will stay in any object for the lifetime of the destruction delay regardless of what it is.
1624557617839.png

I tried making a script that would immediately destroy the projectile, but it doesn't seem to work. At this point, it might be either a feature we need to request or something Justin would know the answer to (if it exists). The feature we would request is a layer filter for "spawned objects on destruction" and/or a layer variable on "OnImpactEvent" so that we could either spawn a dummy arrow at impact location for certain impact events and not others, or be able to get the layer of the collided object so we could then trigger something there.


The bottom is a FYI.
1, I'm not sure if changing the weapon layer will cause other problems because it's the default.I don't know if the source code calls the weapon layer.One problem I can confirm is that if I change Layer, the weapon will collide with the character who take it. Although maybe this problem can be solved using UltimateCharacterLocomotion.AddIgnoredCollider, it just confirms what I said . The source code calls this weapon layer. This is one, is there any others? I don't know. Need to be familiar with the source code.

You have to change the interaction layers in the "Layer manager" component.
1624556149207.png
You may also need to change them in physics in project settings if you still aren't getting what you want (scroll down). Unchecked prevents those two things interacting with each other.
1624556203343.png
call
 
Last edited:
Ok, I dived into this deeper and figured it out. So atm, sticky layers doesn't do anything at all because the collision mode is "collide." This is more for grenades that will bounce off some objects and stick to others. You could make the arrows bounce off swords, I think, by changing to "reflect", but then I think they could still trigger damage on the rebound, which might not be what you want.

The arrows will stay in any object for the lifetime of the destruction delay regardless of what it is.
View attachment 6262

I tried making a script that would immediately destroy the projectile, but it doesn't seem to work. At this point, it might be either a feature we need to request or something Justin would know the answer to (if it exists). The feature we would request is a layer filter for "spawned objects on destruction" and/or a layer variable on "OnImpactEvent" so that we could either spawn a dummy arrow at impact location for certain impact events and not others, or be able to get the layer of the collided object so we could then trigger something there.


The bottom is a FYI.


You have to change the interaction layers in the "Layer manager" component.
View attachment 6259
You may also need to change them in physics in project settings if you still aren't getting what you want (scroll down). Unchecked prevents those two things interacting with each other.
View attachment 6260
call
Hi DavidC, Thank you so much! That's a good idea.

Besides,I don't find interaction layers in the "Layer manager". Do I not get your point?
 
Your characteer should have the Character Layer Manager component - you can remove your projectile's layer from the layer masks to ensure no collisions with that layer are handled (or vice versa). As DavidC suggested, make sure you also disable collisions between the relevant layers in your project's collision matrix.
 
Your characteer should have the Character Layer Manager component - you can remove your projectile's layer from the layer masks to ensure no collisions with that layer are handled (or vice versa). As DavidC suggested, make sure you also disable collisions between the relevant layers in your project's collision matrix.
1, I'm afraid I didn't catch your meaning. As shown in DavidC's screenshot. I only find EnemyLayers, invisibleLayers, SolidObjectLayers in Character Layer Manager component.Where do I remove projectile's layer?

2, Besides, can you look at my second question? Thank you!:)

Can I add rigidbody component to wielded items, such as sword,shield??...
 
I think you would remove it from SolidObjectLayers in this case.

In theory you could add Rigidbody to held items, but it may produce unexpected behaviour - what are you trying to achieve by doing that?
 
I think you would remove it from SolidObjectLayers in this case.

In theory you could add Rigidbody to held items, but it may produce unexpected behaviour - what are you trying to achieve by doing that?
I'll try to get deeper first, and then give you feedback. The reason I want to add rigidbody is as follows. These are two ideas. I want to know more about which is more suitable for me. Because I also need to refer to block ability to play block animation when the arrow hits the shield.

2,Can I add rigidbody component to wielded items, such as sword,shield?? Because the default is not.

I have found the reason for the third problem.Because in Project.Oncollision (raycast? hit), assigned the parent of the projectile to hit.value.transform.gameObject. Hit.value.transform needs to be a rigidbody. Use arrow and shield as example. If the shield is not a rigidbody, it will try up to get shield's rigidbody parent , that is the arm. So, the arrow will be a subobject of the arm.But if so, there are two problems. One is that it can't meet my needs. The other is that there is a hand joint between the arm and the shield. The animation of the hand joint makes it look like the arrow doesn't stick tightly to the shield,there is a dynamic offset.
 
Last edited:
1, I'm afraid I didn't catch your meaning. As shown in DavidC's screenshot. I only find EnemyLayers, invisibleLayers, SolidObjectLayers in Character Layer Manager component.Where do I remove projectile's layer?

2, Besides, can you look at my second question? Thank you!:)

Can I add rigidbody component to wielded items, such as sword,shield??...

You click on each of those drop downs to get a whole other menu to enable and disable layers. For example, I added a new layer for "ground." I had to add this to Solid Layers. Easy Build System has a layer for "sockets" (snapping points) which are an invisible layer. I also added a "movement" layer for capsule colliders, which were both invisible and solid layers.

1624633330020.png

Enemy Layers​

Layer Mask that specifies the layer that the enemies use.

Invisible Layers​

Layer Mask that specifies any layers that are invisible to the character (such as water or invisible planes placed on top of stairs).

Solid Layers​

Layer mask that specifies any layers that represent a solid object (such as the ground or a moving platform).



 
You click on each of those drop downs to get a whole other menu to enable and disable layers. For example, I added a new layer for "ground." I had to add this to Solid Layers. Easy Build System has a layer for "sockets" (snapping points) which are an invisible layer. I also added a "movement" layer for capsule colliders, which were both invisible and solid layers.

View attachment 6286




OK,I get it. Thank you so much!
 
Glad you figured out the layers part - I'm not exactly sure which parts of the rigidbody question you're still looking at, but let us know if there's anything else you're not sure about.
 
Glad you figured out the layers part - I'm not exactly sure which parts of the rigidbody question you're still looking at, but let us know if there's anything else you're not sure about.
Hi Andrew, thanks for your ask!

I still have one piont need to confirm. It may take two days. I will give you feedback then.

I need to let block ability identify arrows and bullets, because I currently let AI character can block arrows with sword. But at present, it will also block the bullets, which is unreasonable. Because source block ability is for melee weapon,so it needs to be expanded. I haven't checked the source code yet, because I have other work in hand at present. It will take me two days to finish this series of work before I can finally confirm the issues we discussed. Then I'll give you feedback. If you have some ideas on how to identify shootable weapons with block aibiliy like melee weapons, I hope you can give some suggestions.

The main problem should be that need to get the Item ID of the attack shootable weapons for Item Substate Index.
AAABBBCCC
AAA: First three digits indicate the Item ID of the melee weapon that the opponent is attacking with. The ID is an integer so any leading zeros will be truncated
 
The OnImpact provides attackerObject, which is the object that actually hit/shot the player, so you could use that as a starting point - e.g. you can check the name of the attackerObject and use that as an indicator, or you could even check the attacker's inventory and find the item ID of the item sharing the same name.
 
The OnImpact provides attackerObject, which is the object that actually hit/shot the player, so you could use that as a starting point - e.g. you can check the name of the attackerObject and use that as an indicator, or you could even check the attacker's inventory and find the item ID of the item sharing the same name.
Back to our original discussion. So far, both ways work. Thank you so much!
 
Top