playMaker

Author Topic: How to do hit detection?  (Read 1357 times)

paradiseprime

  • Full Member
  • ***
  • Posts: 105
How to do hit detection?
« on: January 02, 2019, 02:11:27 AM »
Ok so the way I decided to do the raycast method which I am finding a lot more precise. I raycast from the my hand to the tip of the weapon and I compare the game object hit with a tag and send an event and stats of the weapon to the fsm of hit object's manager.

The issues I am having are sending damage only once. At the moment if the raycast pasts through the target it fire damage several times before turning off. How do I solve this?

Next issue is getting hit at the same time by multiple different sources of damage. If 2 weapons attack at the same time how do I get both damage values from both weapons to register?

Also has anyone found an answer to animation events not playing because of blending happening before it gets to that frame?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: How to do hit detection?
« Reply #1 on: January 02, 2019, 05:50:41 AM »
Hi.
Can you show your setup (fsm/states) so we can see whats wrong.

Probably you will need to do a delay after the raycast before triggering the next shot.

How are you deducting the damage?

Event will indeed not trigger when it does not reach the frame.
You will have to rethink how you can do this differently
« Last Edit: January 02, 2019, 05:52:44 AM by djaydino »

paradiseprime

  • Full Member
  • ***
  • Posts: 105
Re: How to do hit detection?
« Reply #2 on: January 02, 2019, 11:06:42 AM »
Ok so on further testing I think I found a solution that still needs testing but is the best version so far.

The way I have it atm is:

*Have a raycast from my hand to the tip of the weapon and compare everything it goes through by tag.

*The array is checked to see if the target is already listed. If it is then it goes back to raycast detection. If not then it sends the damage values of the weapon as floats to the name specific fsm of targets hit.

*While ^ happens a timer that control the time between hits counts down with a timer of .5 (gonna change it so that it is synced with the animation instead of a fixed time which makes it more precise) but .5 is a wait time because the attack is longer than .5 meaning only 1 instance of damage can be done at a time.

*The event is sent to a fsm on the enemy that does the damage and then locks itself from receiving anymore damage until that calculation is done then unlocks.

paradiseprime

  • Full Member
  • ***
  • Posts: 105
Re: How to do hit detection?
« Reply #3 on: January 02, 2019, 11:08:22 AM »
Here are the other 4 images

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: How to do hit detection?
« Reply #4 on: January 03, 2019, 02:14:26 AM »
Hi,
Looks good, let us know after some testing if its working the way you want it to.

A side note :
Name your states. (for example on the state you are doing a raycast, name it raycast)

Use the description (write what you are doing inside the fsm/states)

Later on when you need to do some changes in your have you will be happy you did....believe me, i learned that the hard way :)