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 Rukiryo · Feb 11, 2014 at 04:08 AM · networkingserverrpcclientnetworkview

Networking: RPC To Specific Player?

Hi, I'm new to networking and have got a game working where me and my friends can fly planes together. To add bullets and nametags, each plane needs to be identified. I have a few questions.

1) How do I speak specifically to one object, in everybody's game? Like if Plane A shoots Plane B, I want to send an RPC call to all clients (from the server) saying that Plane B is to take damage. The RPC call will trigger on every plane, so how do I specify a specific plane?

2) The planes have a networkview on their transform. They fly fairly smoothly but there is definite jitter. How can I make them fly smoothly? Prediction?

Thanks a ton!

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 sumeetkhobare · Feb 11, 2014 at 08:36 AM 0
Share

I am in doubt myself for the jitter, but yeah I can answer first question. Why don't you try sending the networkView as an argument to the RPC call. and then, in the RPC function check if the received networkView is of the player B and then apply damage? this way, assume Player C, would find that its not its own networkView and it wont apply damage.

Hope this helps.

1 Reply

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

Answer by xt-xylophone · Feb 11, 2014 at 11:41 AM

For starters Ive only used Photon Network, not Unity's Networking but they are quite similar.

For 1, you can choose the Network Player of the the RPC, check the bottom: http://docs.unity3d.com/Documentation/ScriptReference/NetworkView.RPC.html

For 2, Yeah that will happen if its just the transform. What you want to do is make a custom script to sync the transform smoothly. Ive used this all the time:

 using UnityEngine;
 using System.Collections;
 
 public class NetworkTransform : Photon.MonoBehaviour {
     private Vector3 correctPlayerPos = Vector3.zero; // We lerp towards this
     private Quaternion correctPlayerRot = Quaternion.identity; // We lerp towards this
 
     
     void Update() {
         if (!photonView.isMine) {
             transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 5);
             transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 5);
         }
     }
 
     void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
         if (stream.isWriting) {
             // We own this player: send the others our data
             stream.SendNext(transform.position);
             stream.SendNext(transform.rotation);
         } else {
             // Network player, receive data
             this.correctPlayerPos = (Vector3)stream.ReceiveNext();
             this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
         }
     }
 }

What this does is it smoothly moves to the most recent rotation and position received as well as sending it out. Just make this what the network view is listening to. This is also for PhotonNetwork, so no copy+pasting, but hopefully it can put you on the right track!

I usually extend this so I can sync anything else needed. Its as simple as adding the variables in those 4 places. Good luck!

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 Rukiryo · Feb 11, 2014 at 03:35 PM 1
Share

Thanks a ton!

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

19 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

Related Questions

Networking between projects: how to send ViewIDs? 1 Answer

Networking: Players being "Perma-hit" 0 Answers

Im not being able to fill up variables with RPCs 1 Answer

Sending RPC To Specific Player On All Clients? 0 Answers

UNET Discrete Server/Client. ClientRPC? Command? 3 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