playMaker

Author Topic: Sword damage with trigger colliders or Raycast?  (Read 398 times)

RICK

  • Playmaker Newbie
  • *
  • Posts: 29
    • View Profile
Sword damage with trigger colliders or Raycast?
« on: April 28, 2019, 03:53:17 PM »
Hi,
I've tried to use colliders as triggers on my sword with animation events to turn the colliders on and off at the right moments. I have an FSM that receives the events to turn the colliders on and by using activate game object actions. The animation events consistently fires the on and off events but the activate game object does not seem to work consistently. I ran a test to fire the collider on event and stop in that state to see if the activate game object action turned on the collider, it rarely did. I read that with this kind of setup for collision, the animation may be to fast for the events to fire properly. My animation events are firing properly but the activate game object part is not working. Any way to make this work?

I was looking into using raycast. I shoot a ray from the base of the blade to the tip. My enemy npc have colliders on all of its body parts. When the sword hits the npc, the hit object is stored. No matter where I hit the enemy, the hit object is always the parent of the body parts. This is where I have trouble and confusion. I need to get the child of the parent that was hit, correct?
I was thinking that I need to use an array in this process so I tried to learn about and use arrays.
I ran into problems with getting and storing variables in the array, I have a previous post about that problem. Can anyone tell me in detail from the moment my raycast hit the parent object as to how I proceed? I don't even know if I need to use an array.

Thanks,

RICK

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4615
    • View Profile
    • jinxtergames
Re: Sword damage with trigger colliders or Raycast?
« Reply #1 on: April 29, 2019, 01:20:35 AM »
Hi.
There is an action called : Enable Collider, maybe that one works better.

for raycast, you can use layers to ignore certain layers.
You could ignore the parent or look only for 'body parts' layer.

Give a 'body parts' layer to all the body parts that could be hit

for this case you probably do not need an array.

miguelfanclub

  • Full Member
  • ***
  • Posts: 152
    • View Profile
Re: Sword damage with trigger colliders or Raycast?
« Reply #2 on: April 29, 2019, 04:03:45 AM »
If what youre doing involves fast movement you will need for sure raycast, or make collisions bigger, but then you will have more problems regarding that.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4615
    • View Profile
    • jinxtergames
Re: Sword damage with trigger colliders or Raycast?
« Reply #3 on: April 29, 2019, 05:39:56 AM »
Hi.
In a 2d game i am working on we use a polygon collider which covers the complete swing of the sword.
this way the collider does not need to move with the swing, only with the player movement.

and we enable/disable the collider when the sword can hit something.

RICK

  • Playmaker Newbie
  • *
  • Posts: 29
    • View Profile
Re: Sword damage with trigger colliders or Raycast?
« Reply #4 on: May 01, 2019, 07:54:59 PM »
Hey djaydino,
Thanks for the tips. First I tried to work with using box colliders on my sword. I had 8 colliders on the blade, I tried to increase the size of the enemy npc body part colliders but that didn't work. The animation events( Collider-on, Collider-off ) triggered every time. The events are sent to an FSM that turns the collider game objects on and off, one state turns the colliders on and another state turns them off. Each state uses the activate game object action. I set up a test, I made a state machine that alternates between the collider on and collider off states with the activate game object and wait actions as in ths screen shot.  I found that below .3 seconds wait, the transition between the states became inconsistent. I also found out that when the sword colliders passed through the body parts collider, it didn't trigger the on trigger enter on the body parts collision FSM. I think the movement is to fast going through the colliders. I increased the time between the Collider-on and Collider- off events as much as I could but that didn't work. My project is a 3rd person RPG and I want precision body part collisions. I want to implement dismemberment later on and it would be more realistic.

I looked into using raycast. I had an empty game object at the base of the sword blade, at the critical point in the attack animations, an animation event fires the raycast set for the length of the blade. The hits were inconsistent, so I  set up up 3 Points in front of the player, parented to the player animator game object which acts as high, mid and low attacks. I categorized all the attacks this way and set up the appropriate animation event to fire off the raycast accordingly. I got good results and I think I will use this method.
 
Thanks again  djaydino, seeing my player and enemy npc is getting more complex, I will probably run into something I will need help with.

Thanks,

RICK

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4615
    • View Profile
    • jinxtergames
Re: Sword damage with trigger colliders or Raycast?
« Reply #5 on: May 02, 2019, 12:30:07 AM »
Hi.
I also use on trigger stay instead of trigger enter, which may increase consistency.

But i think you are on the right track by using raycasts

Prestonh

  • Playmaker Newbie
  • *
  • Posts: 30
    • View Profile
Re: Sword damage with trigger colliders or Raycast?
« Reply #6 on: May 04, 2019, 10:49:53 AM »
Hi,
I've tried to use colliders as triggers on my sword with animation events to turn the colliders on and off at the right moments. I have an FSM that receives the events to turn the colliders on and by using activate game object actions. The animation events consistently fires the on and off events but the activate game object does not seem to work consistently. I ran a test to fire the collider on event and stop in that state to see if the activate game object action turned on the collider, it rarely did. I read that with this kind of setup for collision, the animation may be to fast for the events to fire properly. My animation events are firing properly but the activate game object part is not working. Any way to make this work?

I was looking into using raycast. I shoot a ray from the base of the blade to the tip. My enemy npc have colliders on all of its body parts. When the sword hits the npc, the hit object is stored. No matter where I hit the enemy, the hit object is always the parent of the body parts. This is where I have trouble and confusion. I need to get the child of the parent that was hit, correct?
I was thinking that I need to use an array in this process so I tried to learn about and use arrays.
I ran into problems with getting and storing variables in the array, I have a previous post about that problem. Can anyone tell me in detail from the moment my raycast hit the parent object as to how I proceed? I don't even know if I need to use an array.

Thanks,

RICK
.

I dont know if youve looked into these but. 
Animation events,  if are placed too early or too late, can cause issues with animation transition blending happening.   
Collider on dynamic constant detection?
Ive switched to a collider that covers the entire area of the swing all at once.   Then use the animation event at the pinicle of the swing to send a hit event to anything in the collider.  Works great for me, may not be good for you.