playMaker

Author Topic: [SOLVED]Photon 2 Spawning a GameObject in AR in the same position on all clients  (Read 1853 times)

serenefox

  • Full Member
  • ***
  • Posts: 135
    • Serenefox Games
I am trying to spawn a bomb from a player in my multiplayer game in AR. The reason I mention this is because when I place my AR arena its in one position but the other player may place theirs somewhere else and the arena positions are different.

The bomb does not have a photon view on it so when I press the bomb button I have, I send an RPC with the bombs position to all clients. Then I subtract the arena position that was placed from the sent bomb position and spawn the bomb. I am doing something wrong because the bomb is not in the correct position on any of the clients when it spawns. Is there a certain formula for this that I am missing? I feel like there needs to be a relative or shared point I need to compare to.

Thanks for any info!
« Last Edit: June 12, 2020, 11:54:41 AM by serenefox »
Most Recent Published Games:
Juicy Theater - Android

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 you are likely having a problem of relation between your AR world position between each client.

 usually, this means you should switch your AR settings so that the camera moves instead of the Actual Ar marker or Ar Ground, then your world content doesn't change and all positionning is consistent across all applications running in the same environment with obvious different AR camera position.

https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@1.0-preview.8/api/UnityEngine.XR.ARFoundation.ARSessionOrigin.html#UnityEngine_XR_ARFoundation_ARSessionOrigin_MakeContentAppearAt_Transform_Quaternion_

it's tricky, so be patient :)

Bye,

 Jean

serenefox

  • Full Member
  • ***
  • Posts: 135
    • Serenefox Games
Hi Jean,

I did some research on the documentation you linked to and tried to implement it. I can't get it to work properly.

I tried using MakeContentAppearAt() in Update with the AR camera as my content, and a world vector as 0,0,0. I get an error "screen position is out of camera frustum" and I can't see where my arena is placed. I believe it is because the AR camera is a child of the AR session origin gameObject.

I also tried placing the arena and then calling MakeContentAppearAt() with the arena as the content and world position as zero, but that just makes my arena move to world zero when I call that and I have to physically turn to find it. So that's not a good option.

I'm not sure what I am missing, but I don't think I am understanding what you said about moving the camera versus moving the marker. Doesn't the AR camera move regardless as the device moves?

My current setup is:

1. My scene loads and the AR camera is activated/tagged to main camera if my global AR variable is true) and the default camera is turned off/set to untagged because it is an AR scene.

2. I ArRaycast into the world and detect planes.

3. In Update, the arena I have is placed at the intersection of the detected planes and the Ray.

4. I can scale the Ar Session Origin dynamically so the arena fits the right size.

5. I confirm the placement at the position. Then find a game.

Will those placement steps work with the MakeContentAppearAt method? If so what am I missing in my logic?

Thanks for any info!
Most Recent Published Games:
Juicy Theater - Android

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 I did struggle big time myself, and the fact that there is no preview or simulation possible in editor, it makes the process highly frustrating, so be patient and don't give up.

the post below is to be studied in great details, and test the samples provided and extensively try to understand how it all works. That thread was the base for me to make it work.

 https://forum.unity.com/threads/scaling-with-arfoundation.543953/

regarding camera vs marker movement:

when the device AR engine detects the marker, there is a relation between the Device and the marker in the real world ( the distance, and angle between the device camera and the marker). Now you have two ways to transpose that in the virtual world, you can either move the AR Camera or move the Marker.

By Default the marker is moving, but with MakeContentAppearAt(), the marker stays at the transform it was set during editing, and the AR camera is moving instead.

That's it.

Bye.

 Jean

serenefox

  • Full Member
  • ***
  • Posts: 135
    • Serenefox Games
Hi Jean!

I got it working. It finally clicked after reading this part of your comment:

Quote
regarding camera vs marker movement:

when the device AR engine detects the marker, there is a relation between the Device and the marker in the real world ( the distance, and angle between the device camera and the marker). Now you have two ways to transpose that in the virtual world, you can either move the AR Camera or move the Marker.

By Default the marker is moving, but with MakeContentAppearAt(), the marker stays at the transform it was set during editing, and the AR camera is moving instead.

I was previously still trying to set the marker in my placement logic, then finalize it with the MakeContentAppearAt method, which moved the arena itself anyway like default. What I just did after reading your comment was use MakeContentAppearAt in the Update method WHILE "placing" my arena, which did what you said. Now everything works and is at world zero even though it doesn't appear so in AR mode.

Thank you again Jean!
Most Recent Published Games:
Juicy Theater - Android

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Hi,

 good!

Bye,

 Jean