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 awdawdawd · Aug 16, 2012 at 06:54 PM · collidernetworkprojectileignore

Network - Projectile, Prevent Collision with Parent

Hello,

I'm working on a multiplayer network game. Pretty simple concept, just kill any other player you see.

Right now, I'm working on a throwing knife, although I'm sure the concept can be applied to any projectile, but my problem is that the knifes collider colliders with my character/player on initiation.

Few things crossed my mind to prevent this:

1) I could give the knife a 'Projectile' tag and go into my Unity Physics Settings and prevent collision with 'Projectile' and 'Player'. The simple problem with this, is that all the 'networked' players also have the tag 'Player', and thus would ignore their collider too.

2) I'm currently using a system where by the throwing knife collider starts off as a trigger, and then after about 0.1 second, turns the trigger collider off, so its a normal collider on. This works, because by the time the collider is active, its well out of reach by the user, this just doesn't seem very ... genuine?

3) I tried messed around with the 'Physics.IgnoreCollision' but I was having no luck!

Because this is a network game, I would normally use Instantiate.Network, so I'm not sure if the Physics.IgnoreCollision applies?

Anyway, here is my code that throws the knife:

 function Update(){
      if(Input.GetButtonDown("Action")){
           if(networkView.isMine){
                networkView.RPC("ThrowKnife", RPCMode.All, shooterID.viewID, levelDamage[level]);
     }
      }
 }
 
 @RPC
 function ThrowKnife(shooterID : NetworkViewID, damage : float){
     
     child.animation.Play("KnifeSwing_Throw");
     
     PlayAudio(0, knifeSwing);
     
     yield WaitForSeconds(0.1);
             
     levelObjects[level].active = false;
         
     var knife : Rigidbody;
     knife = Instantiate(throwingKnife, levelObjects[level].transform.position, player.transform.rotation); //Network.
     
     yield WaitForSeconds(3);
     
     levelObjects[level].active = true;
     throwing = false;
 }

So, actually right now I'm just using a normal Instantiate, and not a Network one. But I would like to know if it is possible with a Network one too?

Any ideas?

EDIT ---

My characters (well all the characters in the game) do not use a normal collider, they are using a Character Controller.

Thanks

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
Best Answer

Answer by gegc · Aug 16, 2012 at 07:36 PM

Physics.IgnoreCollision() is the "right" way to do it. Keep in mind that, unlike what you have now, Network.Instantiate should not be called in an RPC because it is itself an RPC and spawns the object on all clients. So if you're using Network.Instantiate, you will probably want an RPC immediately following the spawning of the projectile to tell all the clients to uncollide it from the player. So something like:

 //Assuming this is in the player class.
 void ThrowKnife() {

     GameObject knife = 
      (GameObject)(Network.Instantiate(knifeFab,herp,derp,NETWORK_INSTANTIATES));

     NetworkView.RPC("RemoteDoThrowKnife",
         RPCMode.OthersBuffered,knife.networkView.viewID);

     //don't forget to call the function on yourself, because Unity
     //won't call RPC's on the RPC source even if you use RPCMode.All!
     RemoteDoThrowKnife(knife.networkView.viewID);
 }
  
 //then later,
 [RPC]
 void RemoteDoThrowKnife(NetworkViewID knifeID) {  

     //tell clients to play animations, etc

     //uncollide the objects
     Rigidbody knifePhysics = NetworkView.Find(knifeID).gameObject.rigidbody;
     Physics.IgnoreCollision(this.rigidbody,knifePhysics,true);
 }


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 mikebelotti · Aug 16, 2012 at 07:27 PM

Interesting. I would try giving the knife an "owner" reference (could just be a `GameObject`) that `ThrowKnife` sets manually when the knife is created. That way, in your `OnTriggerEnter` or `OnCharacterControllerHit`, you can compare the character that got hit with the knife to the knife's owner.

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

10 People are following this question.

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

Related Questions

How to do a frontal-only shield of sorts? 1 Answer

Colliders won't work (Closed) 2 Answers

Network - Firing Projectile RPC Issue? 1 Answer

Make raycast ignore some objects. 2 Answers

How to check if two objects are mutually ignoring collision? 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