HELP! Dodgeball game!
Options
My game requires players to pick up balls by parenting the object to the players hand and changing their positions + throwing them by adding force to the balls rigidbody.
I need help with making the balls sync over the network. Is their a easier way to just change the position of the ball for all players and sync the rigidbody? How will i go about this?
Heres the Throw&PickUp Code:
I need help with making the balls sync over the network. Is their a easier way to just change the position of the ball for all players and sync the rigidbody? How will i go about this?
Heres the Throw&PickUp Code:
using UnityEngine; using System.Collections; public class Thowing : MonoBehaviour { public float ballHoldTimer = 5; float ballTimer; int ammo = 0; [SerializeField] private Camera playerCamera; [SerializeField] public LayerMask mask; public float maxThrowForce = 2000; public float throwForce = 2000; public float pickUpRange = 3; public GameObject ball; public Transform ballSpawnPoint; bool canShoot = false; bool canCatch = true; Animator anim; public GameObject arms; GameObject thrownBall; void SetDefaults() { ballTimer = ballHoldTimer; anim = arms.GetComponent<Animator> (); } void Start() { SetDefaults (); } void Update () { if (Input.GetKeyDown (KeyCode.Mouse0) && canShoot) { Throw (); } if (Input.GetKeyDown (KeyCode.Mouse1) && canShoot) { Block (); } if (Input.GetKeyDown (KeyCode.Alpha1)) { throwForce = maxThrowForce; } if (Input.GetKeyDown (KeyCode.Alpha2)) { throwForce = maxThrowForce/2; } if (Input.GetKeyDown (KeyCode.G)) { float lastTF = throwForce; throwForce = 5; Throw (); throwForce = lastTF; } if (Input.GetKeyDown (KeyCode.E)) { Shoot(); StartCoroutine (GrabAnim()); } if (Input.GetKeyDown (KeyCode.F)) { StartCoroutine (FakeAnim()); } if (ammo >= 1) { ammo = 1; } if (ammo <= 0) { ammo = 0; } if (ammo == 1) { canShoot = true; } else { canShoot = false; } if (ballTimer <= 0 && canShoot) { Throw (); ballTimer = 0; Debug.Log ("You were holding a ball too long!"); } } void Shoot() { RaycastHit hit; if (Physics.Raycast (playerCamera.transform.position, playerCamera.transform.forward, out hit, pickUpRange, mask)) { if (hit.collider.tag == "Ball" && canCatch == true) { StartCoroutine (GrabAnim ()); ballTimer = 0; ballTimer += ballHoldTimer; ammo += 1; thrownBall = hit.collider.gameObject; thrownBall.GetComponent<Rigidbody> ().isKinematic = true; thrownBall.transform.position = ballSpawnPoint.position; thrownBall.transform.rotation = ballSpawnPoint.rotation; thrownBall.gameObject.transform.SetParent (ballSpawnPoint); thrownBall.layer = LayerMask.NameToLayer ("Weapon"); thrownBall.GetComponent<AudioSource> ().enabled = false; Debug.Log ("Picked Up Ball"); } } } IEnumerator GrabAnim() { if (canCatch == true) { anim.SetTrigger ("Grab"); canCatch = false; yield return new WaitForSeconds (0.5f); canCatch = true; StopCoroutine ("GrabAnim"); } } IEnumerator FakeAnim() { if (canCatch == true) { anim.SetTrigger ("Throw"); canCatch = false; yield return new WaitForSeconds (0.1f); canCatch = true; StopCoroutine ("FakeAnim"); } } IEnumerator ThrowAnim() { anim.SetTrigger ("Throw"); yield return new WaitForSeconds (0.20f); StopCoroutine ("ThrowAnim"); } void FixedUpdate() { if (canShoot) { ballTimer -= 1; } else { ballTimer = 0; } } void Throw() { thrownBall.gameObject.transform.SetParent(null); thrownBall.layer = LayerMask.NameToLayer ("Ball"); thrownBall.GetComponent<Rigidbody> ().isKinematic = false; thrownBall.GetComponent<Rigidbody>().AddForce (thrownBall.transform.forward * throwForce); thrownBall.GetComponent<AudioSource> ().enabled = true; StartCoroutine (ThrowAnim()); ammo -= 1; } void Block() { } void OnTriggerEnter(Collider col) { if (col.tag == "Ball") { } } }
0
Comments
-
It is basically acting like a grenade - If anyone has a script they are willing to share for a grenade code or something please help0
-
No actual help on you question, however, I would like to point out the "code" formatting option. Makes code things a lot more readable.0