Cant drag ARKit SCNNode?
I agree with @Rickster that the Apple Code
provides a much more robust example, however, I have this and it seems to work smoothly (much more so when you are using PlaneDetection (since feature points are much more sporadic):
I don't make use of touchesBegan
but simply do the work in touchesMoved
instead:
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
//1. Get The Current Touch Point
guard let currentTouchPoint = touches.first?.location(in: self.augmentedRealityView),
//2. Get The Next Feature Point Etc
let hitTest = augmentedRealityView.hitTest(currentTouchPoint, types: .existingPlane).first else { return }
//3. Convert To World Coordinates
let worldTransform = hitTest.worldTransform
//4. Set The New Position
let newPosition = SCNVector3(worldTransform.columns.3.x, worldTransform.columns.3.y, worldTransform.columns.3.z)
//5. Apply To The Node
nodeToDrag.simdPosition = float3(newPosition.x, newPosition.y, newPosition.z)
}
I might be going about this completely the wrong way (and if I am I would love to get feedback).
Anyway, I hope it might help... You can see a quick video of it in action here: Dragging SCNNode
Placing, Dragging and Removing SCNNodes in ARKit
The solution for dragging the object was to set the movedObject to the [[[hitResult node] parentNode] parentNode] parentNode] and the drag became smoother.
Related Topics
Detect Moment When Newline Starts in Uitextview
Calayer - Cabasicanimation Not Scaling Around Center/Anchorpoint
Swift Add Footer View in Uitableview
Set Delegates to Nil Under Arc
iOS Input Focused Inside Fixed Parent Stops Position Update of Fixed Elements
Presenting Uialertcontroller from Uitableviewcell
Opening Word,Excel, and PDF Files Without Using Uiwebview on iOS
Xcode 8 Swift 3 Uitableview Space Between Cells
Core Data Store Included in App Bundle
Swiftui in iOS14 Keyboard Avoidance Issues and Ignoressafearea Modifier Issues
How to Import Existing Objective C Classes in Swift
Change the Alpha Value of the Navigation Bar
iPad - Parsing an Extremely Huge JSON - File (Between 50 and 100 Mb)
How to Implement Uitableview's Swipe to Delete for Uicollectionview
Flutter:Not Connecting to iOS Simulator in Android Studio
Detect and Use Optional External C Library at Runtime in Objective-C
Storyboard Instantiateviewcontrollerwithidentifier Not Setting Iboutlets