I currently have melee scripted in for a diablo-esque type of game. When I click on an enemy, the enemy is stored as a GameObject. When I swing, if they are still in range, I call their getHit function. This works fine. So tonight I coded in the shift modifier and it works just how you would expect the shift key to work in a diablo game. Only issue now is that I no longer have an enemy object to call the getHit function. I have thought of a couple ways that might work but I thought I’d ask for advice first to see if anyone has any insight into the best way of accomplishing this. Any advice would be much appreciated. Thanks!
Before you call the getHit function check to see if the enemy game object exists. if not return out to prevent the call.
Thanks Troy but I don’t have a game object when I use the shift modifier. He just swings regardless or not an enemy is present. This works perfect fine. The issue I am looking to resolve is how do I catch whether or not I actually hit something. I’m thinking I need to treat this more like a projectile and create a mesh that spawns at the hit point and then cycle through finding the closest target and doing damage to that one (for single target melee). I wasn’t sure if there was another way that people have found that would be easier. Thanks
Why not put a collider on the sword. When it hits something have it check a list of tags. If the tag is an enemy then get component and call the getHit function. If the tag is a wall call then call a function to make a wall hitting found.
That is another idea. I would have to turn the collider off unless I was at the climax of my swing because it would collide as I was running around and not attacking. I know games like Diablo 3 has a large arc where you can do damage to someone. Trying to mimic what they are doing just trying to decide how to do it. Thanks!
I have never played Diablo but to solve the hitting random things just have a bool called duringSwing. Then when it collides with an object check to see if that variable is true or false.