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 DynamicPrgm · Feb 05, 2013 at 09:26 PM · instantiatenetworkbullet

Lacking Network.Instantiate Knowledge

I have a plane with a gun that shoots a bullet by instantiating a bullet prefab with a bullet physics/damage application script attached. I need this to work over the server, so should I use network.instantiate for it?

Comment
Add comment · Show 1
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 Dave-Carlile · Feb 05, 2013 at 09:46 PM 1
Share

Yes, you should.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by AndrewGrayGames · Feb 05, 2013 at 10:17 PM

Answer #1: Yes. You absolutely should use Network.Instantiate() from the server.

Looking forward, when your clients fire their weapons, they should use an RPC (R emote P rocedure C all, pretty much a public facing function) which talks to the server and tells it to instantiate a bullet at the muzzle's position and rotation.

You'll be getting a lot of milage out of RPCs, too; when an instantiated object moves, the server should calculate the move, and send an RPC to each of the clients to tell them to perform the move. That's a different, but related topic.

Other cool gameplay events? RPCs also.

Another thing to know: When your bullet is done, make sure you Network.Destroy() the object so that all your clients see it destroyed, again on the server.

Comment
Add comment · Show 3 · 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 DynamicPrgm · Feb 05, 2013 at 11:47 PM 0
Share

For the movement of the bullet, shouldn't I use Network View on the bullet prefab so it can be synchronized? Or would I just instantiate it and it would go where the script would take it on all the clients?

Also, the plane is shooting quite a lot of these bullet prefabs, so would it slow down the server?

Thanks for the useful answer!

avatar image DynamicPrgm · Feb 06, 2013 at 12:47 AM 0
Share

Another thing, to do that in code I would use this:

 @RPC
  
 var bullet : Transform;
  
 function Shoot(){
  
 Network.Instantiate(bullet, transform.position, transform.rotation, 0);
 yield WaitForSeconds(.2);
  
 }
  
 function Update(){
  
 if(Input.GetButton("Fire"))
 {
 Shoot();
 }
  
 }

Right? I'm not on a computer with Unity at the moment. I would attach this to the empty gameobject at the end of my plane's weapons.

avatar image AndrewGrayGames · Feb 06, 2013 at 08:05 PM 0
Share

@DynamicPrgm: Yes, make sure your moving entities have a NetworkView!

A performance impact would be deter$$anonymous$$ed by a number of factors - server RA$$anonymous$$/processor speed, bandwidth, and performance hits from scripts. It's conceivable that your 'bullet hell' plane could be firing as many as you need and only imperceptibly slow your game.

And yes, that script would work on the muzzles on your mesh! I can't test it either, but that code looks good.

avatar image
0

Answer by lacost · Feb 05, 2013 at 10:26 PM

you don't need instantiate here, just use RPC

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 AndrewGrayGames · Feb 05, 2013 at 10:35 PM 0
Share

While the clients may not need Instantiate, the server does. In turn, the server will need to tell the clients to instantiate a local game object so everyone is on the same page. Given the OP's question involves the server, I would not say that he does not need Instantiate.

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

12 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

Related Questions

Network.Instantiate players at each spawnpoint? Don't use the same spawnpoint? 1 Answer

PhotonNetwork.Instantiate 2 problems. 3 Answers

Network.Destroy and collision; destroying correct object. 1 Answer

Spawning the right prefab with Network.Instantiate 0 Answers

Checking if object intersects? 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