Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by danmartyn · Oct 29, 2011 at 11:22 PM · collisioncharacter controller

Detecting Collision Between Player and Enemy

Hey All,

I'm having some major problems with this one. I have a player bot that can run around the scene. It has a character controller used for moving it around and animating and works great. I have an enemy bot (also with a character controller for moving) that right now is just standing in the scene. I'm trying to implement a tag type game, so I want the player to be able to run up to the bot and "touch" it (have the colliders touch) and make whichever one of them is currently not it, it, and vice versa.

I have the function OnControllerColliderHit in the player controls, and with some debug calls can detect the ground, a wall I have in the scene, but NOT the enemy bot! I tried adding the same function to the enemy bot and it doesn't call anything. I thought maybe it would only work if both bots are moving when they collide, so I tried the function on a patrolling bot and ran into him, but no such luck.

Here's the code I'm using:

  function OnControllerColliderHit (hit : ControllerColliderHit) {
     if (hit.collider.gameObject.name != "Ground") {
         Debug.Log("controller = " +hit.controller);
         Debug.Log("gameObject = " + hit.gameObject);
         Debug.Log("transform = " +hit.transform);
         Debug.Log("hit: " +hit.collider.gameObject.name);    
     }
     
 }

I'm just trying to see how to detect that enemy bot. I've been trying to work on this the last few days and it's killing my brain. I was able to use RayCasting to detect the other bot, but the problem (I was using a sphere ray cast), was that if I stood right on the boundary between the two bots, it would flip back and forth very quickly and it was more random whether or not the Player would come out it, or not it.

Any ideas guys?

Dan

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ninjarob · Oct 30, 2011 at 09:02 PM

ok try this create a script called Tag

public var isIt:boolean = false;

 function OnCollisionEnter(collision : Collision) {
   var tag:Tag = collision.gameObject.GetComponent("Tag");
   if(tag && isIt){
     tag.isIt=true;
     isIt=false;
   }
 
 }

You'll need to set one of the player to be It at the start and put the tag script on all players involved

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

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

My Character Controller Is Warping Randomly (/w video) 0 Answers

Controller area of collision/contact 0 Answers

A Character Controller with another shape. 0 Answers

Character Controller giving false collisions 0 Answers

Destory Character on Collision with Plane 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges