I am interested in making fighting/hack n slash games (basicly, games that involve hitting stuff ;)). Anyways, I was wondering how I would go about handling the colliders/hit boxes? For example, if I am doing just a simple punch in a fighting game,when the button is pressed, would I spawn a new trigger where the bunch would be? Would it be easier to move existing colliders(would it be a good idea to set up a series of colliders, move them other positions, and then have them be translated to the second position when a button is pressed)? I know that was a vague question, but thanks.
Nothing? I dont need anybody to code anything for me, I am just asking for some advice.
You shouldn’t have to spawn colliders. You can get hit points from the OnCollisionEnter() function. You just need to declare a variable inside the function. The Collision class gathers info on the point of the collision, the magnitude, what was hit, etc which is stored in the hit variable.
OnCollisionEnter (hit : Collision)
Or if you’re using a character controller, you use OnControllerColliderHit()
If you need more specificity, I suppose you can put empty game objects on the hands and feet as children of the player character and add colliders or triggers to these. I’m sure there are examples on these forums or in the Lerpz tutorial on how to handle this. But the idea of moving colliders around or spawning them at some point where a collision is about to occur defeats the purpose. Their purpose is to detect the collisions in the first place.
I think the reason you’re not getting a clear answer is that there seems to be a basic misunderstanding of how colliders are used. You might want to check out the tutorial videos at www.unity3dstudent.com to get a better grasp of how all this works.
Okay, so I dont need to spawn new colliders. But if I have a sword object(with a collider attached to it), I would still need to translate the position of the object forward, sideways, etc. if I want to a slash attack, right?
yes, you would make it a child of the player’s arm so they move together by default. You would just move the arm in local space (which means relative to the player parent object) not world space. But you’re better off creating these animations separately in your 3D modeling software. Then you can just call the animation. This is not an area I know well. I’m not a modeler (yet), but others may be able to offer opinions on that.
and then it would just be something like this attached to the enemy object:
static var life = 3;
OnCollisionEnter(collision : Collision) {
if (other.CompareTag ("Weapon")) {life-=1;
}
}
Yes, that would work. Just be a little careful of the static variable. They can be tricky. You may be better off accessing a regular public variable by referencing the script and the variable:
otherScript.life