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 Mint92 · Apr 09, 2014 at 10:56 AM · rotationnetworkrpcclientturret

Getting rotation to work on client

Hey guys,Ive created a turret script which basically allows the player to press the up and down arrow. The turret its self is controlled by an empty game object. Ive got that working locally but how do i get it to work on client side. My tutor told me it was similar to the way the position works. like this:

 void Update ()
 {
 if(Input.GetButtonDown("Right"))
             {
                 transform.position = new Vector3(transform.position.x + 1.0f, transform.position.y,transform.position.z);
             }
             else if(Input.GetButtonDown("Left"))
             {
                 transform.position = new Vector3(transform.position.x -1.0f, transform.position.y,transform.position.z);
             }
             
             if(Vector3.Distance(transform.position,lastPosition) > 0.05);
             {
                 networkView.RPC("Log", RPCMode.Server, "Client " + owner + " is moving");
                 
                 lastPosition = transform.position;
                 networkView.RPC("SetPosition", RPCMode.Others, gameObject.name, transform.position);
             }
 
 }
 
 
     [RPC]
     public void SetPosition(string shipName, Vector3 newPosition)
     {
         // find the local version of the ship
         GameObject ship = GameObject.Find(shipName);        
         
         networkView.RPC("Log", RPCMode.Server, "Updating position of " + ship.name + " to " + newPosition);
         ship.transform.position = newPosition;
     }


how much different is to find the rotation of my turretscript.?

this is my turret script:

 using UnityEngine;
 using System.Collections;
 
 public class TurretControl : MonoBehaviour 
 {
     public NetworkPlayer owner;
     public float minForce, maxForce, forceIncrement;
     public float force;
     private int speed = 1;
     private float maxRotationZ;
     private float minRotationZ;
     
     void Awake()
     {
         enabled = false;
     }
     
     void Start()
     {
         minForce = 100;
         maxForce = 5000;
         forceIncrement = maxForce * 0.05f;
         force = (maxForce - minForce) / 2.0f;
         maxRotationZ = 0.5f;
         minRotationZ  = -0.1f;
     }
         
     void Update ()
     {
         if(Input.GetKey(KeyCode.UpArrow))
         {
             if (transform.rotation.z <= maxRotationZ)
             {
                 transform.Rotate(0, 0, Input.GetAxis("Vertical") * speed);
             }
         }
         
         if(Input.GetKey(KeyCode.DownArrow))
         {
             if (transform.rotation.z >= minRotationZ)
             {
                 transform.Rotate(0, 0, Input.GetAxis("Vertical") * speed);
                 
             }
         }
         
         if(Input.GetKey(KeyCode.A))
         {
             force += (forceIncrement * Time.deltaTime);
             
             if (force > maxForce) force = maxForce;
         }        
         else if(Input.GetKey(KeyCode.S))
         {
             force -= (forceIncrement * Time.deltaTime);
             
             if (force < minForce) force = minForce;
         }
     }
     
     public float getForce()
     {
         return force;
     }
 }
 

 


Comment
Add comment · Show 6
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 Mint92 · Apr 10, 2014 at 12:05 PM 0
Share

Bump, so confused

avatar image Mint92 · Apr 11, 2014 at 12:01 PM 0
Share
 using UnityEngine;
 using System.Collections;
 
 public class ShipController : $$anonymous$$onoBehaviour 
 {
  private Vector3 lastPosition;
  private Quaternion lastRotation;
 }
 void Start () 
     {
         currentAmmo = 1;
         lastPosition = transform.position;
         lastRotation = transform.rotation;
     }
     
     // Update is called once per frame
     void Update () 
     {
         if (game.running && Network.player == owner) 
         {
 if(Input.GetButtonDown("Right"))
             {
                 transform.position = new Vector3(transform.position.x + 1.0f, transform.position.y,transform.position.z);
             }
             else if(Input.GetButtonDown("Left"))
             {
                 transform.position = new Vector3(transform.position.x -1.0f, transform.position.y,transform.position.z);
             }
             
             
             
             
             //Call SetPosition to notifty the client is moving
             if(Vector3.Distance(transform.position,lastPosition) <= 1)
             {
                 networkView.RPC("Log", RPC$$anonymous$$ode.Server, "Client " + owner + " is moving");
                 
                 lastPosition = transform.position;
                 networkView.RPC("SetPosition", RPC$$anonymous$$ode.Others, gameObject.name, transform.position);
             }
             
             if(Quaternion.Angle(transform.rotation,lastRotation)>= -100)
             {
                 lastRotation = transform.rotation;
                 networkView.RPC("SetRotation", RPC$$anonymous$$ode.Others,gameObject.name,transform.rotation);
             }
 
 [RPC]
     public void SetPosition(string shipName, Vector3 newPosition)
     {
         // find the local version of the ship
         GameObject ship = GameObject.Find(shipName);        
         networkView.RPC("Log", RPC$$anonymous$$ode.Server, "Updating position of " + ship.name + " to " + newPosition);
         ship.transform.position = newPosition;
     }
 
     
     [RPC]
     public void SetRotation(string TurretPivotControl, Quaternion newRotation)
     {
         //find the local version of the turretpivotControl
         Transform turret = transform.Find("TurretPivotControl");
         networkView.RPC("Log", RPC$$anonymous$$ode.Server, "Updating rotation of " + turret.name + " to " + newRotation);
         transform.rotation= newRotation;
         
     }

the position works fine.but the turret is not updating. not sure what im missing

avatar image Benproductions1 · Apr 12, 2014 at 04:58 AM 0
Share

Please do not bump unless it's been at least a week or two. It's considered spam and you will get flagged for it :)

avatar image Mint92 · Apr 13, 2014 at 04:38 PM 0
Share

Sorry, but im really stuck and have researched on how to fix the problem. Im getting closer. its just frustrating looking at code for hours.

avatar image Mint92 · Apr 26, 2014 at 12:10 PM 0
Share

this is my problem.alt text

i cant seem to update the turret position on both sides

tank5.png (60.3 kB)
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Mint92 · Apr 27, 2014 at 12:08 PM

Okay, i found out that i needed to have a Network Component attached to the turret as well. which is updating both on server and client.

Comment
Add comment · 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

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

22 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

Related Questions

Clients are not disconnected when Master Server goes shut down 1 Answer

Network Instaniate,Lag,Bullet Prefab 1 Answer

RPC Call Mix Up Issues 0 Answers

Get RPC senders ID, or IP? 1 Answer

RPC is called but it doesn't destroy some GameObject instances 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