Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Ramech · Sep 28, 2015 at 06:39 AM · rigidbodynetworkontriggerenter

Shooting with Gun

Hello, I have a big problem on my FPS :

When I use Mouse0, a bullet appear and have a velocity, but I would like create damages to ennemi when the bullet is trigger with it.

I do this but I got damages and the other player not.

Thanks, Excuse me for my bad English.

(The game is Multiplayer).

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
1

Answer by Ambrose998800 · Sep 28, 2015 at 01:33 PM

Seems to be a problem with your own collider.

Look for 'Layer Collision Matrix' in Edit -> Project Settings -> Physiks. Make sure, your bullet ignores your own player collider by using different layers.

Comment
Add comment · Show 6 · 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 Dark_Seth · Sep 28, 2015 at 02:01 PM 0
Share

If using the collision matrix. Enemies can't use the same bullet prefab. 2nd Prefab with a diff layer that can hit the player.

Or when Instantiating the prefab ignore the collision http://docs.unity3d.com/ScriptReference/Physics.IgnoreCollision.html

 // Instantiate a bullet and make it ignore collisions with this object.
 
 var bulletPrefab : Transform;
 
 function Start () {
     var bullet = Instantiate(bulletPrefab) as Transform;
     Physics.IgnoreCollision(bullet.GetComponent.<Collider>(), GetComponent.<Collider>());
 }
avatar image Ramech · Oct 02, 2015 at 04:07 PM 0
Share

Thanks you, I try that and I will repost :)

avatar image Ramech · Oct 03, 2015 at 02:40 PM 0
Share

It doesn't work :/ I have always the same problem, the player dead with his own bullets and his bullets don't do damage to my ennemi :/

avatar image Ramech Ramech · Oct 05, 2015 at 05:21 PM 0
Share

Any one has the solution of my problem ? :/

avatar image Dark_Seth Ramech · Oct 05, 2015 at 06:28 PM 0
Share

I use both. Both ways work. Post your code and let us have a look.

avatar image Ramech Dark_Seth · Oct 11, 2015 at 06:09 PM 0
Share

Yeah, there are my three script in this zip.

avatar image
0

Answer by Dark_Seth · Oct 12, 2015 at 03:34 PM

Ok. Didn't find any Ignore statements inside. Added this one for you. Just know if gun has the collider and the gun is where the script is attached it will ignore collision with the gun. Might need to add the parent in too.

 public IEnumerator OneShot ()
 {
     //GetComponent<AudioSource>().PlayOneShot(gun.sound);
     canShoot = false;
     gun.bulletsInAmmo --;
     float x, y;


     if (!GetComponent<Crosshair>().isScope)
     x = Random.Range(-(100-(float)GetComponent<Crosshair>().tirAuJugee)/5000, (100-(float)GetComponent<Crosshair>().tirAuJugee)/5000);
     else
     x = Random.Range(-(100-(float)gun.accuracy)/10000, (100-(float)GetComponent<Crosshair>().tirAuJugee)/10000);
     if (!GetComponent<Crosshair>().isScope)
         y = Random.Range(-(100-(float)GetComponent<Crosshair>().tirAuJugee)/5000, (100-(float)GetComponent<Crosshair>().tirAuJugee)/5000);
     else
         y = Random.Range(-(100-(float)gun.accuracy)/10000, (100-(float)GetComponent<Crosshair>().tirAuJugee)/10000);    

     Rigidbody instantiatedProjectile = Network.Instantiate(projectile, transform.position + new Vector3(0, 0, 0), transform.rotation, 0) as Rigidbody;
     instantiatedProjectile.velocity = GetComponent<Transform>().TransformDirection((Vector3.forward + new Vector3(x, y, 0)) * gun.velocity + new Vector3(0, 0, 0));
     //Added
     Physics.IgnoreCollision(instantiatedProjectile.GetComponent.<Collider>(), GetComponent.<Collider>());

     GetComponent<RotateX> ().rotationX = Mathf.Lerp (GetComponent<RotateX> ().rotationX, GetComponent<RotateX> ().rotationX - 0.6f, 1f);
     yield return new WaitForSeconds (gun.rateOfFire);
     canShoot = true;
 }
Comment
Add comment · Show 1 · 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 Ramech · Oct 12, 2015 at 05:35 PM 0
Share

Thank you for all your post, but I already add the IgnoreCollision, in a singleplayer server, my player shoot and he doesn't got damages :)

But when I have two players in a server, if one of two shoot, he dead with his own bullets :/

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

OnTriggerEnter not firing if rigidbody is on its side 0 Answers

OnTriggerEnter2D reacts to child rigid bodies but OnTriggerExit2D does not. Why? 0 Answers

how effect physically on the other game object with rigidbody when collision in the network unet 0 Answers

Can't get trigger to work 1 Answer

Point of contact on other object in OnTriggerEnter 1 Answer


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