Post

Replies

Boosts

Views

Activity

RealityKit - Measuring entity weird - measured from world origin not by entity
I tap screen and get result hit point. from that point, I want to measure distance to a 3d object placed on ar view. code is *for placing 3dobject let anchorEntity = AnchorEntity(anchor: anchor) anchorEntity.addChild(modelEntityClone) arView.scene.addAnchor(anchorEntity) *for point to measure distance to 3dobject guard let rayResult = self.view!.ray(through: normalizedIndexPoint)else {return} let results = self.view!.scene.raycast(origin: rayResult.origin, direction: rayResult.direction) if let firstResult = results.first { var position = firstResult.position var distanceing = distance(firstResult.position, self.me!.position) } I pointed very close to 3d object but it's a bit far saying 30 cm... or so, I found out that once I close to world origin, than it become almost 0... how can I measure from 3d object not from world origin?
0
0
928
Feb ’22
change rotation of anchorEntity in RealityKit
I placed 3d object to ARViewController after 3 seconds of placing object, then I want to rotate object by 90degree arView.scene.addAnchor(anchorEntity) DispatchQueue.main.asyncAfter(deadline: .now() + 3){ print("after 3 sec ! ") let radians = 90.0 * Float.pi / 180.0 anchorEntity.orientation = simd_quatf(angle: radians, axis: SIMD3(x: 0, y: 1, z: 0)) } it works very well but the problem is that I want to smooth rotation , as you can see short video, it suddenly rotate which seem weird. how can I do this ? https://youtu.be/Ixk2elm-bfU
1
0
1.6k
Feb ’22
moving anchor entity to other entity facing
Hello I made a code that there is Entity loaded on ar, and I placed cube to position which is SIMD3 what I want is that moving entity loaded on ar to move to the location where cube is located. how I did is self.modelentity2!.move(to: Transform(scale: simd_make_float3(1, 1, 1),                                                                                            rotation: (anchorEntity.transform.rotation),                                                           translation: newTranslation),                                             relativeTo: nil,                                             duration: 2,                                                                              timingFunction: .linear) self.modelentity2 is entity that I loaded and anchorEntity is that I place when user tap modelentity2 is moving very well to anchorEntity but the problem is that modelentity2 should face toward anchorEntity but it looks rotating randomly or not rotating at all. how can I move entity face to anchorEntity ?
0
0
690
Feb ’22
Moving modelEntity and generatecollisionshape true at the same time
Hello //modelEntityClone.generateCollisionShapes(recursive: true) modelEntityClone.physicsBody = PhysicsBodyComponent(massProperties: .default, material: .default, mode: .dynamic) as above, I have modelEntity placed on arscene, and moving modelentity is very well ! but as soon as adding generateCollisionShape , modelentity is not moving anymore, how can I use both moving entity and generate collision ?
0
0
495
Feb ’22