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 Aridez · Jun 02, 2014 at 04:29 AM · collisionnetworkingphotonshooting

Photon shot collision

Hi everyone!

I'm trying to instantiate a dodgeable shot on a multiplayer game test im trying. So far I got this:

The one who shots:

 public class movement : MonoBehaviour {
 /..code............../
         if (Input.GetMouseButtonDown(0)) {
             GameObject g = PhotonNetwork.Instantiate("shot", transform.position, Quaternion.identity, 0);
 /...more code......./
 
     [RPC]
     void Applydamage(float damage, PhotonMessageInfo info)
     {
      health -= damage;
     }
 }

Here I basically instantiate the shot and set the target of it.

The shot code when it collides with the other player:

 void OnCollisionEnter2D(Collision2D coll) {
     if (coll.gameObject.tag != "me") {
         coll.gameObject.GetComponent<PhotonView>().RPC("Applydamage", coll.gameObject.GetComponent<PhotonView>().owner, damage);
         if (this.gameObject.GetPhotonView().isMine) PhotonNetwork.Destroy(this.gameObject);
     }
 }

I want to point out that when I instantiate a player, I set a "me" tag to make shots only hit others. The problem is that, when I instantiate a shot, the one who shots always gets damaged (like if that applydamage function is called always). The damage done to the other ones is applied correctly, only if hit. What am I doing wrong?

Thanks for your help!

Edit: The one who shots is the one losing health always. When I instantiate the shot the applydamage function is called almost instantly for the one shooting.

Edit2: Looks like it just happens when the shooter is not moving. The function is called out of nowhere (I'm controlling the only rpc call I made and its not even entering on that if so I dont understand what's going on, if someone wants to see the full code or can purpose a simpler way to get this working i'd appreciate it a lot!

Edit3: I think it has something to do when it collider with itself, when moving the shots usually don't collide with you, but when standing still they always do. But I still don't get why, there's only one RPC call and a I use a Debug.log to know when its called, and it is not when standing still. I got something like:

 Debug.log("in2");
 coll.gameObject.GetComponent<PhotonView>().RPC("Applydamage", coll.gameObject.GetComponent<PhotonView>().owner, damage);


And that "in2" is not showing on the console, how can the message be sent then?

Edit4: No matter what the damage dealt is always 1.

Edit5: I get one call to the Applydamage function for each other player in the scene, looks like its called from nowhere and then the parameter is always 1 (for some reason).

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

1 Reply

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

Answer by Arkaic · Jun 02, 2014 at 05:45 AM

I waited a while to see if anyone one with more knowledge then me would reply but I'll give it a shot :p.

What I have done for bullets is I used the RPC function to tell everyone to create the bullets with the normal Instantiate function. The reason for that is it made deleting the objects sooo much simpler.

I used a health script that i attached to players then attached a damage script to the bullet prefab. In the bullet prefab under function OnCollisionEnter(collision : Collision) I checked

if(collision.transform.tag == "Enemy"){ collision.transform.GetComponent(PhotonView).RPC("TakeDamage", PhotonTargets.All, damage); }

The RPC that im calling in that script is a RPC function on the healthscript

@RPC

function TakeDamage(amt : float){ health -= amt; } }

The rpc calls from what i understand always finds the right photon view id so it auto applies the damage to the right player on each game client.

In return you are able to tell everyone to create the bullet in the right position then from there when it accomplishes the things you are checking for you tell make it do a RPC that tells everyone to do what you want.

This method works very well for telling players to create particles/explosions things like that.

I would suggest watching through Quill18Creates multiplayer fps tutorial playslist. https://www.youtube.com/watch?v=AIgwZK151-A&list=PLbghT7MmckI7BDIGqNl_TgizCpJiXy0n9

Hope this helped and wasnt to confusing, i can explain better if need.

Good Luck, Arkaic.

Comment
Add comment · Show 6 · 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 Arkaic · Jun 02, 2014 at 05:58 AM 0
Share

By the way, this is all in Javascript which im sure you noticed lol. I can translate if needed.

avatar image Aridez · Jun 02, 2014 at 06:13 AM 0
Share

What you explain there is more or less what I did (I'm not sure if I understood it correctly). So what you do is a PhotonNetwork.instantiate and then when the collision is done you target everyone? (is that what photontargets.all does right?). Wouldn't that damage everyone?

edit: I guess i'm not understanding well how rpc works yet :/

avatar image Aridez · Jun 02, 2014 at 06:41 AM 0
Share

What I really don't understand is why is the first RPC message sent? When I click to shoot is like sending a message to myself and then to the target hit when the bullet gets there, I don't understand why this happens.

avatar image Arkaic · Jun 02, 2014 at 07:51 AM 0
Share

What im doing is telling everyone through a rpc call to create the bullet/bullets with a normal unity function Instantiate.

The PhotonTargets.All tells everyone to do that function yes. But it tells everyone to do the function to the specific photonview id that the call was made on. I would strongly suggest watching the tutorials i linked you. It will be a huge help in what your trying to accomplish. Just dont actually destroy the players like he $$anonymous$$ches.

Networking is a rather complicated thing and takes a let of toying with to understand completely. Im sorry i couldnt be more of a help.

Good Luck, Arkaic.

avatar image Aridez · Jun 02, 2014 at 01:43 PM 0
Share

Those videos helped me out to figure what was going on, thanks!

Show more comments

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

22 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

Related Questions

Bullet Collision in Networking Game. 0 Answers

Photon/Network - Killing A Client Enemy Unit 3 Answers

Photonview "this" does not exist in current context 1 Answer

Player names all displayed as local player photon 2 Answers

Send gameobject through photon RPC 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