#Hi, I am currently developing a 2 player

1 messages Β· Page 1 of 1 (latest)

stark spindle
#

Normally your physics is handle only be the server.

feral merlin
#

soooooo how could I fix itπŸ˜…

stark spindle
#

I don't know how photon handles network transforms though

feral merlin
#

oh ok

#

but thanks

stark spindle
#

If its client based then the player will have to apply the force to thier own rigidbody

feral merlin
#

thats what I do, the magnet works but I can't "detect" the Imput for the activation of the magnet

stark spindle
#

usually you use an RPC for something like that

feral merlin
#

what is that 😊

stark spindle
#

Remote Procedure Call. They should be in the photon docs somewhere

dry haven
feral merlin
#

Ok I will try that, thanks a lot, I will come back if it didn't work πŸ˜„

feral merlin
#

@stark spindle , @dry haven

dry haven
feral merlin
#

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!

dry haven
# feral merlin how could I fix this?

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

feral merlin
#

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

dry haven
#

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

feral merlin
#

ok so as the recipient I add ,,GameObject.FindGameObjectWithTag("Player2")?

#

or wait player2 is enough

dry haven
#

Who controls a players rigidbody and transform? The server or the client itself?

feral merlin
#

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

dry haven
#

I'm assuming player2 has a view attached to it?

feral merlin
#

yes

dry haven
#

view.RPC("ApplyForceToPlayer2", player2.GetComponent<PhotonView>().Owner, pullForce);

feral merlin
#

let me try that πŸ˜„

#

wooooooooow

#

no errorπŸ‘Œ

#

how do you know that

dry haven
#

Most Unity Networking Libraries use the same principles, just a matter of looking up the syntax

feral merlin
#

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

dry haven
#

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.

feral merlin
#

I will πŸ‘πŸ‘

feral merlin
#

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 πŸ˜…

dry haven
#

Collision and Trigger functions that are built in to Unity do not go inside of Update()

feral merlin
#

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

dry haven
#

Can you send me a picture of your collider on the player?

feral merlin
#

oh yeah

#

you mean in the inspector

dry haven
#

Yes

stark spindle
#

You'll also need to check how physics is handled in Photon. Sometimes only the host/server fires collision events

feral merlin
feral merlin
#

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

dry haven
#

If you do any ignoring, collision events won't fire

feral merlin
#

ok bro I am stupid 🀣

#

isnt there like a matrix menue

dry haven
#

Instead I would just set Is Trigger to true

#

And then you can use OnTriggerEnter

feral merlin
#

ohhhh ok

#

for both players?

stark spindle
#

there is a collision matrix but you don't want to mess with that either

dry haven
#

Just one would also work

stark spindle
#

normally I will just check the Tag or the Layer in the Collision or Trigger event

feral merlin
#

wait let me look up how to use on trigger enter

dry haven
#

It's the same as OnCollisionEnter essentially

#

Except triggers allow for overlapping instead of hitting in to each other

feral merlin
#
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

dry haven
#

Collider2D is the parameter, not Collision2D

feral merlin
#

oh ok

#

now there isn't any warning enymoe πŸ˜„

#

but it is still collider2d collision right?

#

i mean "collision"

dry haven
#

That's just the name, can be whatever you want it to be

feral merlin
#

ohh

#

ok

#

wait i'll test it

#

oh

#

now it is falling through the ground because its a trigger

#

i ticket istrigger right?

dry haven
#

Ah yes, that'll happen lol

#

You may want to use two colliders in that case

dry haven
#

You might have to make the trigger collider on a child object of the players so you can perform the ignore by layer still

feral merlin
#

oh ok

#

ill just make it an empty child object right?

#

with the trigger

dry haven
#

Yeah, would work

feral merlin
#

and do I have to make any changes to the code

dry haven
#

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

feral merlin
#

no it works πŸ˜„

#

but it becomes true and then never goes to false again

#

oh wait

#

i did a mistake

feral merlin
#

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

dry haven
#

🫑

feral merlin
#

xD

#

soooo if I face another problem some time could I maaaaaayybe ask again xDDDDDDDD

#

(I wont ask too much)

dry haven
#

Just ask again in the channel so this thread doesn't drag on beyond its original topic

feral merlin
#

thanks πŸ™‚