- Home /
Collisions between two players
Hey guys. I am making a fighting game with my friend which is going to be similar to Tekken. I am having a little trouble working out how colliders work in regards to the two fighters hitting each other.
What I set up for the movement right now is basically the fighters look in the direction of their opponent as soon as they start moving then they transform.Translate(Vector3.forward charSpeed Time.deltaTime);
This works fine. But when their colliders hit they don't change anything. I have attached rigidbodies to the two fighters also due to the jumping system I have set up and because I thought it would have something to do with collisions.
Answer by bodec · Jan 22, 2012 at 03:22 AM
Don't know if this will work but try using box colliders on your characters. or mesh colliders
Answer by GC1983 · Jan 22, 2012 at 05:16 PM
So you have two separate scripts for the movement and the jump? Im not sure by what you mean if you jump one fighter, the other goes up and across? So if you press jump, the other character moves too?
If you wanted, you could use the LookAt() to ensure the objects face one another at all times.
As for the colliders, Rigidbodies do not create collision, they are pretty much design to create physics to the object. You will still need to put collider objects onto the object. Capsule colliders seem to simulate the best shape of the characters parts if you wish to keep it low polygons.
You can use mesh colliders which actually use the object's mesh as the collider, so its the most accurate. But, it does take up more memory during runtime. When you create the colliders onto the objects, you must be sure theyre set to IsTrigger. This creates a switch. So if IsTrigger is active, it turns off the physics of the collider object. If off, the physics is active and the collision functionality is not.
So what you can do is give the objects a mesh collider as their main solid collision so they wont go through one another, and then attach capsule colliders to the body parts and set them to IsTrigger. That way, when you attach your scripts with either OnCollisionEnter() or OnTriggerEnter(), the collisions should happen. Then just code in what you want them to do in response of making contact.
Hope this helps...
Thanks for the answer GC83
I think I may have a problem in the way it is actually set up Unless I simply need to tell it to do something when it collides to stop the colliders overlapping.
Basically what I have is an Empty GameObject with the fighter mesh as it's child. The Empty GameObject holds a movement script which moves the Empty GameObject and its child (The mesh) The mesh has a capsule collider and rigidbody on it. I use the rigidbody so I can apply an upwards force to create a jump.
The reason I have movement on the Empty GameObject and jump on the mesh is because I couldnt work out if it was ossible to move towards the opponent but remain constrained on the y axis. If I jump with one fighter the other will move up and across which makes everything just go wrong.
Oh not I meant that the characters look at each other on all axis so if one character jumps up, the other will tilt its whole body and topple over.
I ended up working out a solution though! I basically made the look axis of y equal to the height of the fighters at all times so that they only ever look in front of them. I also put the entire movement script on the actual mesh and deleted the empty gameobjects. Collisions are now ok. They kind of vibrate when they run into each other though D:
Here:
//Looks at the enemy function lookAt (){ var point: Vector3 = enemy.transform.position; point.y = 1; transform.LookAt(point); }
Thanks a lot for your efforts everyone!
Your answer
![](https://koobas.hobune.stream/wayback/20220613063230im_/https://answers.unity.com/themes/thub/images/avi.jpg)