alright so I’m having a slight problem. I’m trying to get back into making video games, and so far it’s been going well. Things are coming back to me as easily as riding a bike, however, I’m having a problem with my combat system.
basically, I’m wanting a simple combat system for now, the game is 3D and I’m just trying to get a basic sword swing and shield block system going. However, I’m stuck on the sword swinging part, more specifically, registering the sword hitting another game object and using script to reduce the npc’s health. At first I was trying the old way with using colliders, however it got very messy very quickly, so instead I’ve opted to go the raycast route. At least, I hope that’s the correct route.
I need to have a script that is called when I press say, spacebar. Right now I can verify that the function is being called, however when I use the raycast I can’t get a debug line from it.
void TempAttack(){
Debug.Log ("Function Called");
RaycastHit hit;
Vector3 fwd = transform.TransformDirection (Vector3.forward);
if (Physics.Raycast (transform.position, fwd, 10)) {
Debug.Log ("Raycast Hit");
}
}
any help would be greatly appreciated. I also need to obtain information about the hit target, and if possible call a function on that target’s “Enemy.cs” script.