• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Alismuffin · Jan 21, 2012 at 04:35 PM · colliderscollisionsfighting

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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?

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image GC1983 · Jan 21, 2012 at 08:49 PM 0
Share

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...

avatar image Alismuffin · Jan 21, 2012 at 11:17 PM 0
Share

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.

avatar image Alismuffin · Jan 22, 2012 at 10:53 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Collision with Plane fails 0 Answers

How to make a certain function if an object collides with another object? Been searching it up for 2 months. 1 Answer

Instantiated Object Not "Colliding" as Expected. 2 Answers

Inconsistent Trigger events 1 Answer

Tree collisions do not work 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges