google-ar / arcore-unity-sdk

ARCore SDK for Unity
https://developers.google.com/ar
Other
1.4k stars 400 forks source link

Re-position World Origin #304

Open CJRobertson opened 6 years ago

CJRobertson commented 6 years ago

I was wondering if there is a built in way to re-position the world origin after the AR session starts? To be a bit more specific, ARKit 1.5 has this exact same ability:(https://developer.apple.com/documentation/arkit/arsession/2942278-setworldorigin)

The ideal solution would be to tap on a tracked plane and the entire origin would move to that tapped position.

pablisho commented 6 years ago

Hi, thanks for the feature request. Currently ARCore does not support resetting the world origin. I think what you can do is to add an Anchor in your desired position and set your object's parent transform to the Anchor's transform. Would that work for your use case?

CJRobertson commented 6 years ago

That unfortunately will not work.

The purpose of what I'm asking for would help situations like spectating a traditional multiplayer game like Call of Duty for example (not an AR multiplayer game using cloud anchors). Everything is based off the game's server so if I were to move CoD player #1 in AR (using your suggestion that would then move that player in the AR app's game world position), as soon as the player sends movement data to the server, the server will snap player #1's location on the AR app back to the server position.

For a bit more clarification, let's pretend like the server says the CoD player #1 is camping at location 100, 50, 40 (Unity game world coordinates). If I were to move that player in AR to say 500, 265, 300 (still in Unity game world coordinates), the server will still think that player is camping at 100, 50, 40. You wouldn't have an issue until the player sent movement data to the server. So if the player starts moving and ends up at 150, 70, 40, the server will snap the player in the AR app to that new location forcing you to have to constantly move the player.

That's just one example, but the same idea applies to anything that requires objects placed in Unity editor to stay at their placed location in game world coordinates.

pnarendr commented 6 years ago

@pablisho , what you suggested would work for me: I need to establish anchors relative to a permanent augmented image marker and find them again in a new session. Can you please help with some pointers on how to achieve this (elaborate on your comment"I think what you can do is to add an Anchor in your desired position and set your object's parent transform to the Anchor's transform" with some pseudocode perhaps?

aefox commented 6 years ago

@pnarendr the unity android cloud anchors example has this exact same code you're looking for. here's the gist:

// Instantiate Andy model at the hit pose.
var andyObject = Instantiate(_GetAndyPrefab(), m_LastPlacedAnchor.transform.position, m_LastPlacedAnchor.transform.rotation);

// Compensate for the hitPose rotation facing away from the raycast (i.e. camera).
andyObject.transform.Rotate(0, k_ModelRotation, 0, Space.Self);

// Make Andy model a child of the anchor.
andyObject.transform.parent = m_LastPlacedAnchor.transform;

Here's the github link for the code.

pnarendr commented 6 years ago

Thanks!!

On Thu, Sep 6, 2018, 2:18 AM Alexandru Enache notifications@github.com wrote:

@pnarendr https://github.com/pnarendr the unity android cloud anchors example has this exact same code you're looking for. here's the gist:

// Instantiate Andy model at the hit pose.var andyObject = Instantiate(_GetAndyPrefab(), m_LastPlacedAnchor.transform.position, m_LastPlacedAnchor.transform.rotation); // Compensate for the hitPose rotation facing away from the raycast (i.e. camera).andyObject.transform.Rotate(0, k_ModelRotation, 0, Space.Self); // Make Andy model a child of the anchor.andyObject.transform.parent = m_LastPlacedAnchor.transform;

Here https://github.com/google-ar/arcore-unity-sdk/blob/master/Assets/GoogleARCore/Examples/CloudAnchors/Scripts/CloudAnchorController.cs#L193's the github link for the code.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/google-ar/arcore-unity-sdk/issues/304#issuecomment-418990928, or mute the thread https://github.com/notifications/unsubscribe-auth/AX9dq8nPF6uOgabX5-R_TgKzzumZbw5gks5uYMxHgaJpZM4VKZY0 .

pnarendr commented 6 years ago

BTW, is there a corresponding code using Android ARCore?

rvilardo commented 5 years ago

is there any updates on this?