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 Alanimator · Mar 26, 2014 at 04:50 PM · c#networktimerpc

Slow time for every enemy at a certain distance from inside RPC

SO i'm creating a slow motion effect that can be used against enemies when they are at a distance of 200 or less away from "me"(player).

here is the RPC code. it work to the point where it slows the time down across the network but it is slowing time for every single player and not just those who are at a distance of 200.

this script is placed on my player.

     [RPC]
     void SlowTimeForEveryEnemyCloseToMe( float TScale)
     {
                 // check which team i am on 

                 if (TeamImOn == "Red") {
                         if (GameObject.FindGameObjectsWithTag ("blueTeam") != null) {
                                 gos = GameObject.FindGameObjectsWithTag ("blueTeam");
                         }
             
                 }
                 if (TeamImOn == "Blue") {
                         if (GameObject.FindGameObjectsWithTag ("redTeam") != null) {
                                 gos = GameObject.FindGameObjectsWithTag ("redTeam");   
                         }
             
                 }
                 // check distance
         try
         {
                 foreach (GameObject go in gos) {
                         float dist;
                         dist = Vector3.Distance (go.transform.position, transform.position);
                         if (dist < 200.0f) {
                  
                     Time.timeScale = TScale ;
                         }
                 }
         }
     catch
     {
         return;
     }
     }
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 g0tNoodles · Mar 26, 2014 at 04:55 PM 0
Share

From what I can tell, this is checking if any RPC is less than 200 away from you.

You may need to add in some kind of boolean value where is checks if that specific RPC is close.

Something like:

 if(this.transform <= 200)
 {
    Time.timeScale = TScale;
 }

However, I assumed time scale was for the whole game, not just one object but I may be wrong

avatar image Lo0NuhtiK · Mar 26, 2014 at 05:03 PM 0
Share

If you're talking about a slow-mo effect like something how the wizards do in Diablo 3, then you're affecting the other specific in-range characters and not the games timeScale. While the other characters are under the effect you'll have to temporarily change their attributes/etc.

eg :

 OnTrigEnter()
 {
    moveSpeed = slowedSpeed ;
    animationSpeed = slowAnim ;
    attackSpeed = slowAtk ;
 }
 
 OnTrigExit()
 {
    moveSpeed = normalSpeed ;
 ...etc etc...
 }

http://docs.unity3d.com/Documentation/ScriptReference/Time-timeScale.html

avatar image Alanimator · Mar 26, 2014 at 05:29 PM 0
Share

thanks g0tNoodles but i think that would bring about the same effect maybe even a bit more problems.

thanks Lo0Nuhtik ,i think that would be a bit tedious for me to implement right now , besides i'm trying to slow the entire scene of the close enemies and not just the players themselves.

1 Reply

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

Answer by fholm · Mar 27, 2014 at 09:37 AM

If you are using an authoritative setup, this would be the responsibility of the server. If you are not running a central server, each client would check their own slowmo-state.

For the non-server approach, this is the basics:

1) Send an RPC to the NetworkView of the object which has the slowmo effect around itself 2) This sets a bool which says slowmo active/not active 3) On each local client, you check if they are within range of another player which has "slowmo" set to true (and its on the other team) 4) If they are slow them down, if they are not, speed them up

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 Alanimator · Mar 28, 2014 at 02:35 AM 0
Share

In my case the server can act as a player also. I wont be able to do that because "Send an RPC to the NetworkView of the object which has the slowmo effect around itself" does not exist for me .

i'm basically trying to tell all the enemies withing a 200 unity radius that "hey , you are close to me, take this RPC". so prior to the player sending the RPC there really is no slow motion function initialized across the network.

avatar image fholm · Mar 28, 2014 at 05:10 AM 1
Share

And I'm saying that this is the wrong way to go about things, synchronize the state of the object which has the Slow$$anonymous$$o effect around it ins$$anonymous$$d, and then figure out when to activate/de-activate it for each client locally ins$$anonymous$$d. It uses less bandwidth and it leads to a more consistent world since the clients don't need to be notified by RPC when they go in/out of the slow-motion field.

avatar image Alanimator · Mar 28, 2014 at 06:03 AM 0
Share

ooh now i understand , that "Send an RPC to the NetworkView of the object which has the slowmo effect around itself" confused me . because of how it was worded .

that should definitely work without a problem.

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

23 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

Related Questions

RPC and multiplayer networking 2 Answers

Why I am getting JSON error during the query of Internet Time? 1 Answer

Check bool on another player 1 Answer

Multiple Cars not working 1 Answer

How to send timestamp via RPC so it was relative to the receiver? 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