Unity Community


View Poll Results: Please select each option you agree with (you can select multiple options)

Voters
199. You may not vote on this poll
  • I like that the videos are covering a complete project.

    172 86.43%
  • I find the videos are detailed enough for me to understand and follow.

    151 75.88%
  • I find the video quality is clear enough.

    141 70.85%
  • I find the audio quality is clear enough.

    139 69.85%
  • The narrator doesn't send me to sleep.

    109 54.77%
  • In general the topics covered are interesting.

    130 65.33%
  • I find the website useful.

    103 51.76%
  • The Gamer To Game Developer logo looks good.

    89 44.72%
  • I would like to suggest topics that GTGD should cover in the future.

    77 38.69%
Multiple Choice Poll.
Page 5 of 27 FirstFirst ... 3456715 ... LastLast
Results 81 to 100 of 523

  1. Location
    Gothenburg, Sweden
    Posts
    1,726
    Just a short question:
    You don't use the built in way of syncing the player movement, instead you are using RPCs, what is the pro of doing your way vs the built in way of syncing?
    Current game: Age of Settlement


  2. Posts
    206
    Quote Originally Posted by Virror View Post
    Just a short question:
    You don't use the built in way of syncing the player movement, instead you are using RPCs, what is the pro of doing your way vs the built in way of syncing?
    I'm not sure which is the pro way but I find using RPCs to be easier on my brain. State synchronization relies on data being constantly sent and your network views will have to be observing something I'm pretty sure. You might also have to make use of OnSerializeNetworkView which I've never bothered to do because it just seems like too much code.

    I also find that using RPCs gives me much cleaner movement. If you left the send rate at 15 then the motion of your players is very jerky across the network. With RPCs it is way smoother and the RPCs are only sent when a player is moving. If you increased the send rate then I believe you'll have a whole lot more data being sent needlessly, well that's my current understanding.

    Here are two links from Unity that I found quite important and you might have already seen them.

    http://unity3d.com/support/documenta...kElements.html

    http://unity3d.com/support/documenta...tworkView.html

    If you learn something different please do come back and tell me about it and by the way your planned project looks pretty interesting, and I think you're onto something exciting, so don't let it fizzle out!


  3. Posts
    206
    A YouTube viewer OneManArmy3D posted up that he was having trouble with video 9 because he's programming in JavaScript which does not support delegates.

    I've pasted here some logic that I've developed for sorting a list of numbers without using delegate, and it's in C#, but you should be able to replicate this in JavaScript.

    Just create a new C# script, name it CompareAndSortNumbers, paste in this code and then attach the script to an empty GameObject or Camera. When you run the game the log will show that the list has been sorted.

    Code:  
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. /// <summary>
    6. /// This script can be attached to the main camera or any
    7. /// empty gameobject. When the code runs some predefined
    8. /// numbers are added to List1 and these are then compared
    9. /// and added in descending order into List2.
    10. /// </summary>
    11.  
    12. public class CompareAndSortNumbers : MonoBehaviour {
    13.    
    14.     //Variables Start___________________________________________
    15.    
    16.     private List<int> List1 = new List<int>();
    17.    
    18.     private List<int> List2 = new List<int>();
    19.    
    20.     private int counter;
    21.    
    22.     //Variables End_____________________________________________
    23.  
    24.     // Use this for initialization
    25.     void Start ()
    26.     {   
    27.         //I'll add some numbers to our List1.
    28.        
    29.         List1.Add(12);
    30.        
    31.         List1.Add(1);
    32.        
    33.         List1.Add(4);
    34.        
    35.         List1.Add(8);
    36.        
    37.         List1.Add(7);
    38.        
    39.        
    40.         //I want List2 to be the same size as List1 so I'll add
    41.         //entries into List2 until it is the same size.
    42.        
    43.         for(int i = 0; i < List1.Count; i++)
    44.         {
    45.             List2.Add(0);   
    46.         }
    47.        
    48.        
    49.         //Compare the elements within List 1 and copy them
    50.         //into List2 in descending order.
    51.        
    52.         for(int i = 0; i < List1.Count; i++)
    53.         {
    54.             for(int j = 0; j < List1.Count; j++)
    55.             {
    56.                 if(List1[i] < List1[j])
    57.                 {
    58.                     counter++; 
    59.                 }
    60.             }
    61.            
    62.             List2[counter] = List1[i];
    63.            
    64.             counter = 0;
    65.         }
    66.        
    67.        
    68.         //Now display each element in List2 and you'll see that they are
    69.         //in descending order.
    70.        
    71.         for(int i = 0; i < List2.Count; i++)
    72.         {
    73.             Debug.Log("List2 " + "Index " + i.ToString() + " = " + List2[i].ToString());   
    74.         }
    75.     }
    76. }
    Last edited by GTGD; 04-02-2012 at 03:34 AM.


  4. Location
    Latvia
    Posts
    77
    Thanks again. Here will be in JavaScript:
    Code:  
    1. class CompareAndSortNumbers extends MonoBehaviour {
    2.  
    3.     var List1 = new Array();
    4.     var List2 = new Array();
    5.     var counter : int;
    6.  
    7.     function Start () {  
    8.  
    9.         //I'll add some numbers to our List1.
    10.         List1.Add(12);
    11.         List1.Add(1);
    12.         List1.Add(4);
    13.         List1.Add(8);
    14.         List1.Add(7);
    15.  
    16.         //I want List2 to be the same size as List1 so I'll add
    17.         //entries into List2 until it is the same size.
    18.         for( var k : int= 0; k < List1.Count; k++){
    19.             List2.Add(0);  
    20.         }
    21.  
    22.         //Compare the elements within List 1 and copy them
    23.         //into List2 in descending order.
    24.         for( var i : int = 0; i < List1.Count; i++){
    25.             for( var j : int= 0; j < List1.Count; j++){
    26.                 if(List1[i] < List1[j]){
    27.                     counter++;  
    28.                 }
    29.             }
    30.            
    31.             List2[counter] = List1[i];
    32.             counter = 0;
    33.         }
    34.  
    35.         //Now display each element in List2 and you'll see that they are in descending order.
    36.         for( var u : int = 0; u < List2.Count; u++){
    37.             Debug.Log("List2 " + "Index " + u.ToString() + " = " + List2[u].ToString());    
    38.         }
    39.     }
    40. }


  5. Location
    Gothenburg, Sweden
    Posts
    1,726
    One thing i thought about regarding updating the player position.
    If you move and rotate you will send both rotation and position twice every frame.
    If you instead checked if playerMoved or playerRotated you will only need to send one RPC and will save a lot of bandwidth.
    Current game: Age of Settlement


  6. Posts
    206
    Quote Originally Posted by Virror View Post
    One thing i thought about regarding updating the player position.
    If you move and rotate you will send both rotation and position twice every frame.
    If you instead checked if playerMoved or playerRotated you will only need to send one RPC and will save a lot of bandwidth.
    That's totally true and I do point that out in the upcoming video 12 as we'll be adding a little bit more code to the MovementUpdate script in that video, but at the end of the day I haven't made the script more efficient. Maybe some day I'll change it but for now I leave improving the code from this series to the learner and a lot depends on how they intend to use the code.

    Btw, I'm aiming to get Video 12 Blinking (teleportation) published by this Thursday and it is going to be a totally awesome video and the code is even more awesome!!!


  7. Location
    Gothenburg, Sweden
    Posts
    1,726
    BTW, i love your tutorials, very helpful! : D
    Current game: Age of Settlement



  8. Posts
    75
    Just wanted to drop in an let you know how i was getting along with making the game run using the Unity Master Server.

    I got all of the gameplay working correctly then you released the 'restart match' video and it all got messed up again haha . Have fixed some of the issues that happened but am stuck with 1 final issue.
    Upon restarting the match all players can see and shoot each other (yay!) but only red players take damage. Ive re-watched your video several times and cant quite work out whats going wrong. I remember you mentioning at one point you added code to stop behaviour similar to this but cant find this bit of the video?

    Any ideas where the problem might be? If players disconnect and reconnect then the game runs correctly.


  9. Posts
    206
    It almost sounds like the RPCs for Red players are not being sent across the network because blue players can't take damage, since damage application happens on the attackers computer and that would have to be a red player in order for a blue player to get hurt. This hypothesis isn't true though if you can see that the red players position changes as you move them, as their movement is getting sent by RPCs across the network.

    Maybe the red players are not getting added back to the PlayerList in the PlayerDatabase script?


  10. Posts
    75
    All the players can see each other moving and when shooting you can see the projectiles being created, its just the damage.

    Thanks for the pointer ill checkout the PlayerDatabase script and see if anything is missing there and let you know.


  11. Posts
    75
    Hey think i worked it out. There is nothing wrong with the code i think i was spawning players too quickly because for the moment if once the game has restarted i wait about 5 - 10 seconds before selecting a team then the game plays as normal and all communications are sent correctly. I think its because i set the AssignHealth co-routine to a longer wait duration to allow the health buffering to catch up over the internet since its not LAN based. So i just need to not show the team selection menu until after that duration.

    If this turns out to be the only problem then i will organise the code and post it here, its really only affects a few files. The MultiplayerScript, ReloadLevelScript and a new one i had to make which handles the level loading and for some reason it would only work correctly in javascript


  12. Posts
    78
    Just started to follow your tutorials. I'm on number 3 now. VERY good. Informative, clear and unrushed. Great narrative and I'm learning a lot. Thank You.

    Will there be a series 2 by any chance?

    thanks again.


  13. Posts
    7

    Help!

    Hey Guys Im on Video 10 Currently... But ive managed to come across a few things i may have missed out... if you have skype please post it on here so we may be in contact and you can help me out and maybe remote help me with some coding.

    Bugs/Missed Out:
    When Shooting My Player Gets Moved By The Bullets.
    Player Name Doesnt show above Players.

    Things Needed:
    Master Server
    Weapons

    Hope You can help me guys!

    -Connor


  14. Posts
    206
    I've just completed Video 13 where we’ll implement energy so that the player’s energy weapons and behavior are regulated by how much energy they have!


  15. Posts
    43
    Hi.........
    First, thanks a lot.... for this tutorials ..... One of the best I've ever seen .........
    Well ..... Now the problem I have .........
    I have completed the level change video,but not work well (as you see in the video), when a team has won, does not re-start the level correctly........



    Where do I can have my error???


    PD- 1 ----- I have unity 3.5
    PD- 2 ------ sorry my bad english


    Thanks


  16. Posts
    206
    Hello technotdc,

    Thanks for posting the video to describe the problem you're facing. Actually it looks like you're having multiple problems.

    First your level is not reloading and I suspect this is because the name of your scene is different from what I named the scene. In your ReloadLevelScript look for this line and supply it with the name of your scene rather than what I named my scene.

    Code:  
    1. Application.LoadLevel("Series 1 Prototype");

    Second I notice that when you click a button to choose a team the options are not going away. I think this might be because in the SpawnScript you have not set matchRestart to false after making use of it. This is my code from the JoinTeamWindow function in the SpawnScript.

    Code:  
    1. if(justConnectedToServer == true || matchRestart == true)
    2.         {
    3.             //If the player clicks on the Join Red Team button then
    4.             //assign them to the red team and spawn them into the game.
    5.            
    6.             if(GUILayout.Button("Join Red Team", GUILayout.Height(buttonHeight)))
    7.             {
    8.                 amIOnTheRedTeam = true;
    9.                
    10.                 justConnectedToServer = false;
    11.                
    12.                 matchRestart = false;
    13.                
    14.                 SpawnRedTeamPlayer();
    15.                
    16.                 firstSpawn = true;
    17.             }
    18.            
    19.            
    20.             //If the player clicks on the Join Blue Team button then
    21.             //assign them to the blue team and spawn them into the game.
    22.            
    23.             if(GUILayout.Button("Join Blue Team", GUILayout.Height(buttonHeight)))
    24.             {
    25.                 amIOnTheBlueTeam = true;
    26.                
    27.                 justConnectedToServer = false;
    28.                
    29.                 matchRestart = false;
    30.                
    31.                 SpawnBlueTeamPlayer();
    32.                
    33.                 firstSpawn = true;
    34.             }
    35.         }

    The third thing I've noticed is that when your cursor unlocks after you won the match you were still able to move around and I believe this is because you've forgotten to include the if(Screen.lockCursor == true) and if(Screen.lockCursor == false) checks in the Update function of Unity's FPSInputController script

    Code:  
    1. private var motor : CharacterMotor;
    2.  
    3. // Use this for initialization
    4. function Awake () {
    5.  
    6.     if(networkView.isMine == true)
    7.     {
    8.         motor = GetComponent(CharacterMotor);
    9.     }
    10.    
    11.     else
    12.     {
    13.         enabled = false;
    14.     }
    15. }
    16.  
    17. // Update is called once per frame
    18. function Update () {
    19.  
    20.     if(Screen.lockCursor == true)
    21.     {
    22.         // Get the input vector from kayboard or analog stick
    23.         var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
    24.        
    25.         if (directionVector != Vector3.zero) {
    26.             // Get the length of the directon vector and then normalize it
    27.             // Dividing by the length is cheaper than normalizing when we already have the length anyway
    28.             var directionLength = directionVector.magnitude;
    29.             directionVector = directionVector / directionLength;
    30.            
    31.             // Make sure the length is no bigger than 1
    32.             directionLength = Mathf.Min(1, directionLength);
    33.            
    34.             // Make the input vector more sensitive towards the extremes and less sensitive in the middle
    35.             // This makes it easier to control slow speeds when using analog sticks
    36.             directionLength = directionLength * directionLength;
    37.            
    38.             // Multiply the normalized direction vector by the modified length
    39.             directionVector = directionVector * directionLength;
    40.         }
    41.        
    42.         // Apply the direction to the CharacterMotor
    43.         motor.inputMoveDirection = transform.rotation * directionVector;
    44.         motor.inputJump = Input.GetButton("Jump");
    45.     }
    46.    
    47.    
    48.     if(Screen.lockCursor == false)
    49.     {
    50.         directionVector = new Vector3(0,0,0);
    51.        
    52.         motor.inputMoveDirection = transform.rotation * directionVector;
    53.     }
    54.    
    55. }
    56.  
    57. // Require a character controller to be attached to the same game object
    58. @script RequireComponent (CharacterMotor)
    59. @script AddComponentMenu ("Character/FPS Input Controller")

    Hope that helps.


  17. Posts
    14
    Hey GTGD,

    Very grateful for your helpful tutes, however I have a bit of a problem that I hope you would help me out with. I have taken some of your code and placed it in my game and I'm having problems with the RPC calls over a network. Basically I have a gravity gun that will help my player to pick up rigidbody objects, however the object movement does not translate over the network so other players can't see me moving the object.

    The gravity gun (mover class) will move 'projectiles' made by the builder class type of player. I have tried to adapt your code to suit my needs and this is what I have so far:

    The projectiles already have the Network View attached to them.

    My gravity gun code is in JS and I added an RPC function (at the bottom) that is modelled after what you wrote for your examples
    Code:  
    1. var catchRange = 30.0;
    2.     var holdDistance = 4.0;
    3.     var minForce = 10;
    4.     var maxForce = 10;
    5.     var forceChargePerSec = 30;
    6.     var layerMask : LayerMask = -1;
    7.      
    8.     enum GravityGunState { Free, Catch, Occupied, Charge, Release};
    9.     private var gravityGunState : GravityGunState = 0;
    10.     private var rigid : Rigidbody = null;
    11.     private var currentForce = minForce;
    12.  
    13.     function FixedUpdate () {
    14.         if(gravityGunState == GravityGunState.Free) {
    15.             if(Input.GetButton("Fire1")) {
    16.                 var hit : RaycastHit;
    17.                 if(Physics.Raycast(transform.position, transform.forward, hit, catchRange, layerMask)) {
    18.                     if(hit.rigidbody) {
    19.                         rigid = hit.rigidbody;
    20.                         //print("rigidPos: " + rigid.transform.position);
    21.  
    22.                         gravityGunState = GravityGunState.Catch;
    23.                        
    24.                         // for debuging, remove it
    25.                         //print("force: " + currentForce);
    26.                     }
    27.                 }
    28.             }
    29.         }
    30.         else if(gravityGunState == GravityGunState.Catch) {
    31.             rigid.MovePosition(transform.position + transform.forward * holdDistance);
    32.             //networkView.RPC("updatePos", RPCMode.All, rigid.transform.position, rigid.transform.rotation);
    33.             if(!Input.GetButton("Fire1"))
    34.                 gravityGunState = GravityGunState.Occupied;
    35.         }
    36.         else if(gravityGunState == GravityGunState.Occupied) {
    37.             rigid.MovePosition(transform.position + transform.forward * holdDistance);
    38.             //networkView.RPC("updatePos", RPCMode.All, rigid.transform.position, rigid.transform.rotation);
    39.             if(Input.GetButton("Fire1"))
    40.                 gravityGunState = GravityGunState.Charge;
    41.         }
    42.         else if(gravityGunState == GravityGunState.Charge) {
    43.             rigid.MovePosition(transform.position + transform.forward * holdDistance);
    44.             if(currentForce < maxForce) {
    45.                 currentForce += forceChargePerSec * Time.deltaTime;
    46.             }
    47.             else {
    48.                 currentForce = maxForce;
    49.             }
    50.             if(!Input.GetButton("Fire1"))
    51.                 gravityGunState = GravityGunState.Release;
    52.                
    53.             // for debuging, remove it
    54.             //print("force: " + currentForce);
    55.         }
    56.         else if(gravityGunState == GravityGunState.Release) {
    57.             rigid.AddForce(transform.forward * currentForce);
    58.             currentForce = minForce;
    59.             gravityGunState = GravityGunState.Free;
    60.             // for debuging, remove it
    61.             //print("");
    62.         }
    63.     }
    64.    
    65.     @RPC
    66.     function updatePos(pos:Vector3, rot:Quaternion){
    67.         if(rigid != null){
    68.             rigid.transform.position = pos;
    69.             rigid.transform.rotation = rot;
    70.         }
    71.     }


    This is the code for the 'projectiles' that the gravity gun will have to move. I copied and pasted your movementupdate script to use on the projectiles so you can ignore the comments
    Code:  
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ProjectileUpdate : MonoBehaviour
    5. {
    6.    
    7.     //Variables
    8.     private Vector3 lastPosition;
    9.     private Quaternion lastRotation;
    10.     private Transform myTransform;
    11.    
    12.    
    13.    
    14.  
    15.     // Use this for initialization
    16.     void Awake ()
    17.     {
    18.         if(networkView.isMine == true)
    19.         {
    20.             myTransform = transform;
    21.             Debug.Log("myPos: " + myTransform.position);
    22.             //Ensure that everyone sees the player at the correct location
    23.             //the moment they spawn
    24.            
    25.             networkView.RPC("updateMovement", RPCMode.OthersBuffered, myTransform.position, myTransform.rotation);
    26.            
    27.         }
    28.        
    29.         else
    30.         {
    31.             enabled = false;   
    32.         }
    33.     }
    34.    
    35.     // Update is called once per frame
    36.     void Update ()
    37.     {
    38.         //If the player has moved at all then fire an RPC to update across the network
    39.        
    40.         if(Vector3.Distance(myTransform.position, lastPosition) >=0.1)
    41.         {
    42.             //Capture the player's position before the RPC is fired
    43.             //This determines if the player has moved in the previous if statement
    44.             Debug.Log("updatePosNow");
    45.             lastPosition = myTransform.position;
    46.  
    47.             networkView.RPC("updateMovement", RPCMode.OthersBuffered, myTransform.position, myTransform.rotation);
    48.         }
    49.        
    50.         if(Quaternion.Angle(myTransform.rotation, lastRotation) >=1)
    51.         {   
    52.             //Capture the player's rotation before the RPC is fired
    53.             //This determins if the player has turned in the previous if statement
    54.            
    55.             lastRotation = myTransform.rotation;
    56.            
    57.             networkView.RPC("updateMovement", RPCMode.OthersBuffered, myTransform.position, myTransform.rotation);
    58.         }
    59.     }
    60.    
    61.    
    62.    
    63.    
    64.     [RPC]
    65.     void updateMovement (Vector3 newPosition, Quaternion newRotation)
    66.     {   
    67.         transform.position = newPosition;
    68.        
    69.         transform.rotation = newRotation;
    70.        
    71.         //Debug.Log("updatePos:" + newPosition);
    72.  
    73.     }
    74.    
    75.    
    76.    
    77.    
    78. }

    Hope you're in a helpful mood, if nt thanks so much for the vids anyway, they're excellent and keep up the gd work!
    Last edited by gormee; 04-10-2012 at 03:10 AM.


  18. Posts
    206
    Hello gormee,

    I've had a brief read and this is what I understand, the projectiles are the objects picked up by the gravity gun, and at the moment you can pick them up in your game, but no one else across the network can see you picking up or moving that projectile. I'm guessing that the Gravity Gun script is attached to the player or a GameObject that is a child to the player.

    I believe that you won't see the update because if you notice in the ProjectileUpdate script it requires if(networkView.isMine == true) and I believe this is only going to be true if the projectile was Network.Instantiated with your player, but then other players will not be able to pick it up.

    I think the RPC in the Gravity Gun script has no effect because the other instances of this Gravity Gun script across the network on your player character across the network don't know what rigid is referring to. Only on your instance of the game does the script know what rigid is. In the RPC you would actually have to find the object and tell it what rigid is.

    Here are two rough solutions that I can think of:

    Possible solution 1
    Supply the RPC in the Gravity Gun script with the name of the projectile it has picked up. Please note that each projectile would need a unique name. In the RPC find this projectile GameObject by it's name and then update it's position and rotation with the pos and rot you supplied to the RPC, across the network. I've read from people more knowledgeable than me that GameObject.Find is apparently quite slow and expensive so it might not be such a good solution if you will be sending out this RPC a lot.

    Possible solution 2 and probably better than solution 1
    Make the Gravity Gun script access the ProjectileUpdate script and supply it with your player name when you pick it up.

    In the ProjectileUpdate script use a check just like in the HealthAndDamage script where only on your instance of the game is the RPC executed, which in this case would be updating the position of the projectile. Have your ProjectileUpdate script inform itself across the network who its current holder is (would be you) so that the movement update doesn't get fired off by other players who had supplied their name to that object in the past. This is just like how the HealthAndDamage script updates myAttacker across the network and it's important because when the player is destroyed only the last attacker gets the score. When you let go of the projectile, access the script again and remove your name so that you are no longer the holder and do this across the network so there is no way for the projectile to get moved by player's unintentionally. You could even say the holder is now the Server and include the check if(Network.IsServer) and let the server handle updating the movment of the projectile when no one is holding it. Since it has a rigidbody I guess an explosion that has force could cause it to move so you'd want it's position to be updated across the network by the server in such a situation.

    Let me know how you go and once you have it working, if you can, post a video or some screen shots here about your gravity gun as it would be really neat to see it in action.


  19. Location
    Norway
    Posts
    13
    This is a great place to start if you are serious about game development, but have little to no experience. For the more experienced developers the phase might be a bit slow, but several concepts not seen on other development platforms are thoroughly covered by this series.

    I applaud your time and effort put into this GTGD. Thanks to generous individuals like yourself, this community evolves. Keep up the good work, my friend.
    Last edited by Ithkul; 04-10-2012 at 05:33 AM. Reason: typo

Page 5 of 27 FirstFirst ... 3456715 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •