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 fthmrcn · Jan 07 at 07:02 PM · multiplayerunity 2dphoton

Multiplayer game : bullets spawning and direction point is shows different with each players.

alt text

as you can see I am shooting up on my main screen it shows bullets are going up and thats true , but on the other screen (other players) see the bullet going different direction.

Related Codes :

```

private void Update() { HandleShooting(); }

 void HandleShooting()
 {
     if (Input.GetMouseButton(0))
     {
         if(Time.time > shootingTimer)
         {
             shootingTimer = Time.time + shootingTimerLimit;
             //animate muzzle flash
             shootinhAnimation.SetTrigger(TagManager.SHOOT_ANIMATION_PARAMETER);

             //bullet shoot
             CreateBullet();
         }
     }
 }


 private void CreateBullet()
 {
     // playerWeaponManager.Shoot(bulletSpwantPos.position);
     if (!pv.IsMine)
     {
         return;
     }
     else
     {
     pv.RPC("Shoot", RpcTarget.All,bulletSpwantPos.position);
     }
 }

```

Function that instantiate the bullet

```

 [PunRPC]
 public void Shoot(Vector3 spawnPos)
 {
     targetPos = mainCam.ScreenToWorldPoint(Input.mousePosition);

     bulletSpawnPosition = new Vector2(spawnPos.x , spawnPos.y);

     direction = (targetPos - bulletSpawnPosition).normalized;

     bulletRotation = Quaternion.Euler(0, 0, Mathf.Atan2(direction.y, direction.x) * Mathf. Rad2Deg);
 

     if (direction.x < -1 && direction.y > 0)
     {
         BulletPool.instance.FireBullet(weaponIndex, bulletSpawnPostLast[2].position, bulletRotation, direction);
     }

   

     if (direction.x < 1 && direction.y < 1)
     {
         BulletPool.instance.FireBullet(weaponIndex, bulletSpawnPostLast[1].position, bulletRotation, direction);
     }

 
 }


```

nanada.png (143.3 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GetLitGames · Jan 07 at 08:39 PM

Well the first thing I can see is that you made the Shoot() a PunRPC and it gets the mouse input, which you should not do in any RPC (generally speaking). Input should be read before it calls any RPC because those will happen on the other machines. The other thing you should think about is whether or not you will enforce some kind of server enforced system, or if you will just trust the clients. You could just let the client's enforce their own shots with collision and then report the damage. If it's a fast paced game you could just make the clients RPC shoot the projectile in the direction and have local collision destroy it when it hits something - without resolving any damage. The damage would be resolved either by the server or by the client who fired if you want to trust the clients. In the client auth case, the RPC to other clients would simply mimic what you had fired (assuming there is no physics involved, and the projectile can't bounce randomly). This makes the networking very light and you can have lots of projectiles going on and exploding (the explosions can even use physics if they are just for visual effect and not for splitting projectiles which can further collide and do damage). A typical scenario where there would only be a few projectiles on screen at a time (including any other player's projectiles) would be to have the projectile be a networked object and let PUN replicate it and its position and rotation. In that case only one machine will instantiate it. Also, PUN2 already supports a pool for creating objects. The last option would be consider in your design that the host be the server, and only the host creates the projectile (which is again a networked object). So these are some things you will want to consider in your design and the choices you have.

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 fthmrcn · Jan 07 at 10:21 PM 0
Share

Sir , I am appreciate by your help but I am kind of newbie at Photon Pun , here what I understood 1. I should not use mouse input system on multiplayer games , 2. I should not use pooling system for bullets ( because photon pun doing it)

rest of it I didint understand , your reccomendatiton is very importent for me but , both my unity photon knowledge and my english is not very good can you tell me easier :))

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

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

Photon Multiplayer problem - both characters moving with one control 3 Answers

[PUN2] Problem at pushing the other players 1 Answer

Having only one of the same gameobjects in a scene. Photon Pun 1 Answer

Multiplayer board game using photon in unity (Assign 4 pawns to 1 photon player),Digital board game with Photon, assign 4 different coloured pawns to 1 player 0 Answers

Photon - How to name a player? 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