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 Nocternios · Oct 21, 2017 at 06:26 PM · networkingexplosionlocalclient-serverhost

Why is my client player unaffected by a networked explosion?

In my game, players can spawn fireballs. These fireballs, after being spawned, travel in a straight line. Upon impact with, among other things, a player, an explosion occurs, impacting all objects and players within a certain radius.
Like so:

picture showing a before-and-after shot of a fireball impacting a player

Unfortunately, I cannot seem to get this to work in a networked game. The host player is affected by the explosion and is pushed back, but the client player is not, irrespective of which player spawned the fireball. I am testing over LAN using the standard NetworkManager GUI.

The code responsible for the explosion is a script on the fireball and reads as follows:

 private void OnCollisionEnter(Collision collision)
 {
     Collider[] colliders = Physics.OverlapSphere(rb.position, radius);
 
     foreach (Collider hit in colliders)
     {
 
         // Add explosive force on hit objects
         Rigidbody hitRB = hit.GetComponent<Rigidbody>();
         if (hitRB != null)
         {
             //hitRB.AddExplosionForce(force * timeForceFactor, rb.position, radius, 0, ForceMode.Impulse);
             CmdExplode(hit.gameObject, force * timeForceFactor, rb.position, radius);
             //RpcExplode(hit.gameObject, force * timeForceFactor, rb.position, radius);
         }
 
     }
     Destroy(gameObject);
 }

 [ClientRpc]
 void RpcExplode(GameObject hit, float power, Vector3 origin, float radius)
 {
     hit.GetComponent<Rigidbody>().AddExplosionForce(power, origin, radius, 0, ForceMode.Impulse);
 }

 [Command]
 void CmdExplode(GameObject hit, float power, Vector3 origin, float radius)
 {
     hit.GetComponent<Rigidbody>().AddExplosionForce(power, origin, radius, 0, ForceMode.Impulse);
 }

With the above code, only the host player gets jostled around by explosions. If I use the RPC, instead of the Command, only the client player gets moved around by explosions instead, and some minor glitches are introduced. Often, the glitched player is affected by the explosion for the duration of a single frame, before being pulled back to its initial position.

The fireball object is spawned by either player using NetworkServer.spawn, has a network transform and otherwise functions as required. As everything worked fine for the offline version of the game, I am convinced that the error is due to my limited skill in unity networking.
Thanks in advance

explosion-composite.jpg (265.2 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

103 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity networking tutorial? 6 Answers

UNet NetworkServer.Spawn() not working / Failed to spawn server object, assetId= 2 Answers

Creating a client player and a host player in a single device and networking them correspondingly 0 Answers

Networking bullet spawning issues between Host/Client 0 Answers

[Command] not sending to server? 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