Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by DuperCorp_Blackorito · Feb 22, 2016 at 12:55 PM · networkingmultiplayerphotonballgrenade

Help with Photon Networking Dodge Ball Game

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 there 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ΠckUp 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 (); }

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 ().isKinematic = true; thrownBall.transform.position = ballSpawnPoint.position; thrownBall.transform.rotation = ballSpawnPoint.rotation; thrownBall.gameObject.transform.SetParent (ballSpawnPoint); thrownBall.layer = LayerMask.NameToLayer ("Weapon"); thrownBall.GetComponent ().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 ().isKinematic = false; thrownBall.GetComponent().AddForce (thrownBall.transform.forward * throwForce); thrownBall.GetComponent ().enabled = true; StartCoroutine (ThrowAnim()); ammo -= 1; }

void Block() {

}

void OnTriggerEnter(Collider col) { if (col.tag == "Ball") {

} }

}

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Instantiate with Photon 0 Answers

Photon RPC Only Working Halfway 1 Answer

Client Disconnect on Photon Server using MLAPI 0 Answers

Photon ccu question 0 Answers

Unity Photon Player Instantiation 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