#Hi, I am currently developing a 2 player
1 messages Β· Page 1 of 1 (latest)
soooooo how could I fix itπ
I don't know how photon handles network transforms though
If its client based then the player will have to apply the force to thier own rigidbody
thats what I do, the magnet works but I can't "detect" the Imput for the activation of the magnet
usually you use an RPC for something like that
what is that π
Remote Procedure Call. They should be in the photon docs somewhere
One feature that sets PUN aside from other Photon packages is the support for "Remote Procedure Calls" (RPCs). Remote Procedure Calls are exactly what
Ok I will try that, thanks a lot, I will come back if it didn't work π
Roughly, yeah. But that means each client is applying the force on their own locally. And that could lead to desync
how could I fix this?
I mean how do I have to change the code
add an if(!view.IsMine)?
but thanks for the help!
Iβve never used Photon but most networking libraries have components called NetworkTransform and NetworkRigidbody to help you sync transform and rigidbody data.
I would assume Photon has something similar
oh i have added these
without them nothing works
so everything is fine?
It is calles photon transform view classic
and photon rigidbody 2d view
Almost. From what I can tell youβre sending that RPC to everyone. Which means everyone is adding a force. Usually you only want the owner of the rigidbody to add the force.
Since the transform and rigidbody views will sync the force being added for you
ok so as the recipient I add ,,GameObject.FindGameObjectWithTag("Player2")?
or wait player2 is enough
Who controls a players rigidbody and transform? The server or the client itself?
the client
i suppose π
but maybe I did something wrong
this is the line
view.RPC("ApplyMagnetForce", RpcTarget.Others, pullForce);
but I can't change it to view.RPC("ApplyMagnetForce", RpcTarget.player2, pullForce);
no that doesn't work
I'm assuming player2 has a view attached to it?
yes
view.RPC("ApplyForceToPlayer2", player2.GetComponent<PhotonView>().Owner, pullForce);
Most Unity Networking Libraries use the same principles, just a matter of looking up the syntax
BRooooooo thank you really much it works perfectly ππ
I know that i annoy you but can you help me with one more little problem xD
Also just as a recommendation, you may want to consider designing your script as "Magnet" instead of "MagnetP1".
This way you can reuse the script for every player.
I will ππ
Sure
Okkk, wait a second I have to make a screen recording so you can understand
Ok, so I wanted to make the box colliders of both players ignore themselves so the players can walk "through" eachother. It works but when I do this there is the following bug:
this happenes when i start the magnet
so i tried the following
i wanted to make the magnet only work, when the players arent touching each other
(cause i think that should solve the problem)
and i used on collision enter and exit with the following script change
but in unity it says that the function is never used and the debug.log line always prints false
so I am doing something wrong π
Collision and Trigger functions that are built in to Unity do not go inside of Update()
ohhhhh xD
thought i had to do it so it works with multiplayer or something like that
wait let me try
but it still always prints false
You probably just want to do:
void OnCollisionEnter2D(Collision2D collision)
{
if (!view.IsMine) return;
if (collision.gameObject.tag == "Player2")
touching = true;
}
void OnCollisionExit2D(Collision2D collision)
{
if (!view.IsMine) return;
if (collision.gameObject.tag == "Player2")
touching = false;
}
Can you send me a picture of your collider on the player?
Yes
You'll also need to check how physics is handled in Photon. Sometimes only the host/server fires collision events
where can I check this
How are you doing this?
I am using Physics2D.IgnoreLayerCollision(8, 9); in the start function of the player movement script of both players
8 and 9 are their layers
If you do any ignoring, collision events won't fire
there is a collision matrix but you don't want to mess with that either
oh okπ
normally I will just check the Tag or the Layer in the Collision or Trigger event
wait let me look up how to use on trigger enter
It's the same as OnCollisionEnter essentially
Except triggers allow for overlapping instead of hitting in to each other
void OnTriggerEnter2D(Collision2D collision)
{
if (!view.IsMine) return;
if (collision.gameObject.tag == "Player2")
touching = true;
}
void OnTriggerEnterExit2D(Collision2D collision)
{
if (!view.IsMine) return;
if (collision.gameObject.tag == "Player2")
touching = false;
}```
like this?
there is the error OnTrigger2dEnter has an incorrect signature
Collider2D is the parameter, not Collision2D
oh ok
now there isn't any warning enymoe π
but it is still collider2d collision right?
i mean "collision"
That's just the name, can be whatever you want it to be
ohh
ok
wait i'll test it
oh
now it is falling through the ground because its a trigger
i ticket istrigger right?
do this for the normal collider, and then use the other collider as a trigger
You might have to make the trigger collider on a child object of the players so you can perform the ignore by layer still
Yeah, would work
and do I have to make any changes to the code
I don't think OnTriggerEnter will fire in the parent's script, but you can see if it does
You may have to make a script on the child with OnTriggerEnter in it
no it works π
but it becomes true and then never goes to false again
oh wait
i did a mistake
there's a typo here
Bro I don't know how to thank you π
thank you reeeeaaaly much
you can't imagine how much time I spent asking in forums until you replied
π«‘
xD
soooo if I face another problem some time could I maaaaaayybe ask again xDDDDDDDD
(I wont ask too much)
Just ask again in the channel so this thread doesn't drag on beyond its original topic
thanks π