2
votes

So I am working with ARKit trying to learn some of the basics and I was wondering if it's possible to make a 3d object in ARKit follow the user. So for example if I am standing in front of the object and I start to walk away from it after a certain distance the object would walk/glide towards the user. I also want to be able to move about the object in space, so if it is in front of me I can do a full circle around the object and look at it from all angels.

Any references to articles or sample ARKit projects would be greatly appreciated!

2
This question is quite broad and does not have an answer, but many possible that are not objectively qualifiable (performance, lines of code, efficiency in general, etc.), so I'd say it's not exact SO material. I'd recommend posting on Quora for such broad questions. When you have an idea, have written some code and are stuck feel free to post it here and you'll get help! - regina_fallangi

2 Answers

2
votes

ARKit is currently based around sticking objects onto planes (horizontal and vertical). The "reality" component kicks in when in object is fixed in space like most real objects.

I see what you're trying to achieve here though - it's pretty cool.

Behind the scenes, ARKit likely places everything a 3-axis plane (x,y,z), and tracks the users distance away from an object in terms of those 3 axes. If you can tap into that and change the z value of the object, you might be able to simulate a feeling of following the user.

I'm not a super pro at this either though!

Update:

I researched this a bit more. One possible way to achieve what you’re looking for is set the ARSession configuration to AROrientationTrackingConfiguration instead of the default ARWorldTrackingConfiguration. This will allow and object to rotate freely on the x,y,z axes, allowing you to walk around it, lighting etc, but not move, giving the illusion of following the user as it stays the same size in their phone. This might be even easier.

1
votes

The user's position corresponds to the camera's location. This can be retrieved using the pointOfView property of ARSCNView.

To have an object always follow the user, you can thus add this object as a child of the point of view.

If parenting the object under the point of view doesn't really make sense in your case and you want a different node hierarchy, you can still use conversion utils such as simdConvertTransform:toNode: to update the object's transform in delegate callbacks.