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 Emilyanis · Jun 13, 2014 at 05:39 AM · networkingshootingprojectilemultiplayer networkingtanks

Multiplayer tank game

Hi! I creating a multiplayer tank game, and I have some progress with tank/turret position and rotation in network, but now I stuck in shooting, I tried a lot of methods with RPC and another but it doesn't work. Console gives to me a lot of errors about allocatedID and etc.

Here some parts of coaxial MG shooting code:

 function Update(){
     if (networkView.isMine == true && on == true && Input.GetButton(fireKey) && Time.time > nextFire && pammo>0) {
         networkView.RPC("Shoot", RPCMode.All);
     }
 
 @RPC
 function Shoot(){
     ammo -= 1;
     if (ammo==0 && mags>0){
             nextFire = Time.time + reloadTime;
             if (View.outside == false){
             audio.PlayOneShot(reloadSound);
         }
         }
         if (ammo>0) {
             nextFire = Time.time + fireRate;
         }
     var clone : Transform;
     xRec = Random.Range(-0.5,0.5);
     yRec = Random.Range(-0.5,0.5);
     clone = Instantiate(projectile, transform.position, transform.rotation);
     clone.rigidbody.velocity = transform.TransformDirection(Vector3(xRec,yRec,bulletSpeed));
     
     if (View.outside == false){
         audio.PlayOneShot(inShootSound);
     }
     
     yield WaitForSeconds(distToListener/314);
     if (View.outside == true){
         outShootSound.Play();
         outShootSoundDist.Play();
         outShootSoundFar.Play();
     }
 }
 

And here some parts of bullet code:

 function OnSerializeNetworkView (stream : BitStream, info : NetworkMessageInfo) {
     var syncPosition : Vector3= Vector3.zero;
     if (stream.isWriting) {
         rot = transform.rotation;
         syncPosition = transform.position;
             
         stream.Serialize(syncPosition);
         stream.Serialize(rot);
     } else {
         stream.Serialize(syncPosition);
         stream.Serialize(rot);
             
         transform.rotation = rot;
         syncTime = 0f;
         syncDelay = Time.time - lastSynchronizationTime;
         lastSynchronizationTime = Time.time;
             
         syncStartPosition = transform.position;
         syncEndPosition = syncPosition;
     }
 }
 
 function SyncedMovement() {
     syncTime += Time.deltaTime;
     transform.position = Vector3.Lerp(syncStartPosition, syncEndPosition, syncTime / syncDelay);
 }
 
 @RPC
 function FixedUpdate () {
     var hit : RaycastHit;
     if (rigidbody.velocity.magnitude>0) {
         if (Physics.Raycast(transform.position,transform.forward,hit,rigidbody.velocity.magnitude*Time.deltaTime)) {
             transform.position = hit.point;
         }
     }
 }
 
 function OnCollisionEnter (collision : Collision) {
 
     if (collision.transform.name != transform.name){
 
         var contact : ContactPoint = collision.contacts[0];
         var rotation = Quaternion.FromToRotation( Vector3.forward, contact.normal );
         var explosion : Transform;
 
         if (collision.collider.tag != 'Terrain') explosion=Network.Instantiate(metalEffect,contact.point,rotation,1);
         if (collision.collider.tag == 'Terrain') explosion=Network.Instantiate(groundEffect,contact.point,rotation,1);
 
         rand = Random.Range(0,impact.Length-1);
         if (View.outside == true) explosion.audio.PlayOneShot(impact[rand]);
         Network.RemoveRPCs(GetComponent(NetworkView).viewID);
         Network.Destroy(GetComponent(NetworkView).viewID);
     }
 }


P.S Sorry for my bad english)

Comment
Add comment · Show 3
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 Sebian · Jun 13, 2014 at 07:40 AM 0
Share

What is the question? It's a bit vague.

avatar image pottyscotty · Jun 13, 2014 at 08:12 AM 0
Share

Same, I don't understand what you want to know.

avatar image Emilyanis · Jun 13, 2014 at 08:20 AM 0
Share

Sorry for this) I just want to see some multiplayer shooting example, how does it works, how bullet synchronizes with other players, and something else.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Bullet Collision in Networking Game. 0 Answers

Unity Networking Client not calling functions on server 0 Answers

Slow automatic shooting script? 2 Answers

Projectile Firing/Gun script 1 Answer

Multiplayer advanced - Single Player in Multiplayer game, using another Hosting services. 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