Author Topic: Tnet + Standart Ship Kit Help Me  (Read 6679 times)

ibrahim

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 10
    • View Profile
Tnet + Standart Ship Kit Help Me
« on: February 12, 2016, 04:07:51 AM »
Hello All..
I have Tnet pacage and Standart Ship kit pacage..
im trying to make a multiplayer game with them but
im taking problem in cannonballs and heal between clients can you help me with that
please ....
« Last Edit: February 12, 2016, 04:44:10 PM by ibrahim »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tnet + Standart Ship Kit Help Me
« Reply #1 on: February 12, 2016, 07:43:21 PM »
You will need to explain it a lot more than that. Post some code showing what you're doing at least.

ibrahim

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Tnet + Standart Ship Kit Help Me
« Reply #2 on: February 12, 2016, 08:51:48 PM »
Im having problem in canonball throw between clients the cannon script create the cannonball item with script

GameObject go = Instantiate(cannonballPrefab, mTrans.position, mTrans.rotation) as GameObject;

in this way the cannonball an be create in 1 client when im try to shoot i changed the script in

GameObject go = TNManager.Instantiate(cannonballPrefab, mTrans.position, mTrans.rotation) as GameObject;

and i addet object id in prefab but still the cannonballs wont be create in other client and give me the unique id error.
and [TNet] Trying to exute RFC #255 on TNObject #8 before it has been created
« Last Edit: February 12, 2016, 09:00:28 PM by ibrahim »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tnet + Standart Ship Kit Help Me
« Reply #3 on: February 12, 2016, 08:57:30 PM »
Instead of passing a prefab game object, pass its name and place it in the Resources folder. Furthermore, TNManager.Instantiate does not return anything. It's a delayed call. if you need to pass additional data such as velocity, do it by making an RFC.

TNet 3:
  1. TNManager.Instantiate("CreateCB", "Cannonball", true, pos, rot, velocity);
  1. [RCC] GameObject CreateCB (GameObject prefab, Vector3 pos, Quaternion rot, Vector3 velocity)
  2. {
  3.     GameObject go = prefab.Instantiate();
  4.     go.transform.position = pos;
  5.     go.transform.rotation = rot;
  6.     go.GetComponent<Rigidbody>().velocity = velocity;
  7.     go.DestroySelf(5f); // Destroy after 5 seconds
  8.     return go;
  9. }
Note that for things like cannonballs that will only exist for a few seconds, don't bother attaching a TNObject script to them.

P.S. TNManager.Instantiate is a TNet 3 function. In TNet 2 you're just calling Object.Instantiate.

ibrahim

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Tnet + Standart Ship Kit Help Me
« Reply #4 on: February 12, 2016, 09:19:56 PM »
Sir im using the version 2.1 of TNet but im really confuse where i need to add this script you seend to me the file script to me its this down here if you can fix and send me fixed please
  1. using UnityEngine;
  2.  
  3. [AddComponentMenu("Exploration/Cannon")]
  4. public class Cannon : MonoBehaviour
  5. {
  6.         // Cannonball prefab
  7.         public GameObject cannonballPrefab;
  8.  
  9.         // Initial velocity applied to the cannon ball's rigidbody
  10.         public float initialVelocity = 15f;
  11.  
  12.         // Maximum pitch that can be applied to each shot
  13.         public float maxPitch = 25f;
  14.  
  15.         // Maximum angle at which the cannon is able to fire
  16.         public float maxYaw = 45f;
  17.  
  18.         // The firing direction will have this much deviation in degrees
  19.         public float maxAimDeviationAngle = 5f;
  20.  
  21.         // Maximum possible delay that the cannon will fire after pressing the 'fire' button
  22.         public float reactionTime = 0.2f;
  23.  
  24.         // How long it takes for the cannon to recharge
  25.         public float rechargeTime = 2f;
  26.  
  27.         Transform mTrans;
  28.         GameShip mStats;
  29.         float mFireTime = 0f;
  30.         float mRechargeTime = 0f;
  31.         Collider[] mColliders;
  32.         Vector3 mFiringDir;
  33.         float mFiringPitch = 0f;
  34.         float mMaxRange = 1f;
  35.  
  36.         /// <summary>
  37.         /// Calculated maximum range of the cannon based on max pitch and initial velocity.
  38.         /// </summary>
  39.  
  40.         public float maxRange { get { return mMaxRange; } }
  41.  
  42.         /// <summary>
  43.         /// Helper function that calculates the cannon's maximum firing range.
  44.         /// </summary>
  45.  
  46.         float CalculateMaxRange ()
  47.         {
  48.                 // Vertical velocity can be calculated using the pitch and initial full velocity:
  49.                 float velocity = Mathf.Sin(Mathf.Deg2Rad * maxPitch) * initialVelocity;
  50.  
  51.                 // This is how long it will take the fired cannon ball to reach the sea level
  52.                 float time = -velocity / (0.5f * Physics.gravity.y);
  53.  
  54.                 // Now let's calculate the distance traveled horizontally in the same amount of time
  55.                 return Mathf.Cos(Mathf.Deg2Rad * maxPitch) * initialVelocity * time;
  56.         }
  57.  
  58.         /// <summary>
  59.         /// Cache the transform and the ship controlling this cannon.
  60.         /// </summary>
  61.  
  62.         void Start ()
  63.         {
  64.                 TNManager.AddRCCs<Cannon> ();
  65.                 mTrans = transform;
  66.                 mStats = GameShip.Find(mTrans);
  67.  
  68.                 // Calculate the cannon's maximum range
  69.                 mMaxRange = CalculateMaxRange();
  70.  
  71.                 if (mStats != null)
  72.                 {
  73.                         // Ship stats found -- use it as root node
  74.                         mColliders = mStats.GetComponentsInChildren<Collider>();
  75.                 }
  76.                 else
  77.                 {
  78.                         // No ship stats present -- see if there is a rigidbody that can be used as root
  79.                         Rigidbody rb = PirateTools.GetRigidbody(mTrans);
  80.                         mColliders = (rb != null) ? rb.GetComponentsInChildren<Collider>() : GetComponentsInChildren<Collider>();
  81.                 }
  82.         }
  83.  
  84.         /// <summary>
  85.         /// Fire the cannon when ready.
  86.         /// </summary>
  87.  
  88.         void Update()
  89.         {
  90.                 float time = Time.time;
  91.  
  92.                 // We're ready to fire -- fire the cannon
  93.                 if (mFireTime != 0f && mFireTime <= time)
  94.                 {
  95.                         // Recharge time varies from 80% to 120% of the intended duration just to add variety
  96.                         mRechargeTime = time + rechargeTime * Mathf.Lerp(0.8f, 1.2f, Random.value);
  97.                         mFireTime = 0f;
  98.  
  99.                         // Create the cannon ball
  100.                         if (cannonballPrefab != null)
  101.                         {
  102.                                 // Instantiate the prefab
  103.                                 GameObject go = TNManager.Instantiate("CreateCB", "Cannonball", true, pos, rot, velocity);
  104.  
  105.  
  106.  
  107.                                 // Ensure that the newly instantiated object's collider won't collide with our colliders
  108.                                 if (mColliders != null)
  109.                                 {
  110.                                         Collider col = go.GetComponent<Collider>();
  111.  
  112.                                         if (col != null)
  113.                                         {
  114.                                                 foreach (Collider c in mColliders)
  115.                                                 {
  116.                                                         Physics.IgnoreCollision(c, col);
  117.                                                 }
  118.                                         }
  119.                                 }
  120.  
  121.                                 // It's usually a good idea to know who fired the cannon ball
  122.                                 Cannonball cb = go.GetComponent<Cannonball>();
  123.                                 if (cb != null) cb.owner = mStats.gameObject;
  124.  
  125.                                 // Rigidbody is generally expected to be present
  126.                                 Rigidbody rb = go.GetComponent<Rigidbody>();
  127.  
  128.                                 if (rb != null)
  129.                                 {
  130.                                         Vector2 deviation = Vector2.zero;
  131.  
  132.                                         // Deviate the aim a little
  133.                                         if (maxAimDeviationAngle > 0f)
  134.                                         {
  135.                                                 deviation = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));
  136.                                                 deviation.Normalize();
  137.                                                 deviation *= maxAimDeviationAngle;
  138.                                         }
  139.  
  140.                                         // Calculate the initial velocity
  141.                                         Quaternion firingDir = Quaternion.LookRotation(mFiringDir);
  142.                                         Vector3 vel = (firingDir * Quaternion.Euler(-mFiringPitch + deviation.x, deviation.y, 0f)) *
  143.                                                 Vector3.forward * initialVelocity;
  144.  
  145.                                         // NOTE: For physics-accurate results we should append the ship's velocity as well,
  146.                                         // but this makes the auto-aiming logic fail unless the ship isn't moving.
  147.                                         rb.velocity = vel;
  148.                                 }
  149.                                 else
  150.                                 {
  151.                                         Debug.LogWarning("The cannon ball is missing its rigidbody");
  152.                                 }
  153.                         }
  154.                 }
  155.         }
  156.  
  157.         /// <summary>
  158.         /// Start the firing process.
  159.         /// </summary>
  160.  
  161.         public void Fire (Vector3 dir, float distance)
  162.         {
  163.                 float time = Time.time;
  164.  
  165.                 if (mRechargeTime < time && mFireTime == 0f)
  166.                 {
  167.                         Vector3 cannonDir = mTrans.rotation * Vector3.forward;
  168.  
  169.                         // We only want this cannon to fire if the specified direction is close enough.
  170.                         // It wouldn't make sense to fire guns that are on the opposite side of the ship.
  171.                         if (Vector3.Angle(dir, cannonDir) < maxYaw)
  172.                         {
  173.                                 mFireTime = time + Random.value * reactionTime;
  174.                                 mFiringDir = dir;
  175.                                 mFiringPitch = Mathf.Clamp01(distance / mMaxRange) * maxPitch;
  176.                         }
  177.                 }
  178.         }
  179. }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tnet + Standart Ship Kit Help Me
« Reply #5 on: February 12, 2016, 09:31:38 PM »
Email your order # for TNet to support [at] tasharen.com and I can send you a beta copy of TNet 3.

TNet 2 is more complicated, and the code I pasted won't work for it. But the idea is the same. You need to create a RCC (remote creation call) function declaring your object, or use one of TNet's built-in ones if you are not passing any extra data. For example you can use this built-in function:

TNet 2:
  1. TNManager.Create("Cannonball", true, position, rotation, velocity, angularVelocity);
Either way you have to move your cannonball into the Resources folder and rename it to "Cannonball" for it to be loaded.
« Last Edit: February 12, 2016, 09:57:08 PM by ArenMook »

ibrahim

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Tnet + Standart Ship Kit Help Me
« Reply #6 on: February 12, 2016, 09:48:18 PM »
She is giving me and No overload from method 'Create' takes '7' arguments

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tnet + Standart Ship Kit Help Me
« Reply #7 on: February 12, 2016, 09:57:25 PM »
Yeah get rid of "3". Modified it.

ibrahim

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Tnet + Standart Ship Kit Help Me
« Reply #8 on: February 12, 2016, 10:00:05 PM »
Modify to like what to another number or ....

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tnet + Standart Ship Kit Help Me
« Reply #9 on: February 12, 2016, 11:42:49 PM »
I modified the previous reply.

Just so you know, TNet 3 is what's supported right now. TNet 2 is no longer officially supported.