Post

Replies

Boosts

Views

Activity

RealityKit - how to move entity to other entity smoothly
I want to move toy_drummer entity with rotating toward other model entity. as you can see video, firstly, it move very well to left one then, I touch downward box entity but it move weird. video is youtu.be/3rb9W334Uwg modelentity2 is the entity that I want to move modelentityleft & modelentityright are the entity that modelentity2 should go to , so I can call objective entity *code when I touch left box entity to move, if(entity?.parent?.name=="left"){ self.parent.value4="leftarea" if(oktoadd){ self.counting = self.counting + 1 if(counting==1){ var position = firstResult.position let currentMatrix = self.modelentityleft!.transform.matrix let rotation = simd_float4x4(SCNMatrix4MakeRotation( -90.0 * .pi/180, 0,1,0)) let transform = simd_mul(currentMatrix, rotation) self.modelentity2!.move(to: transform, relativeTo: self.me, duration: 1, timingFunction: .linear) DispatchQueue.main.asyncAfter(deadline: .now() + 1.1) { counting=0 } } } } when click downward box entity, if(ent ity?.parent?.name=="down"){ self.parent.value4="downarea" if(oktoadd){ self.counting = self.counting + 1 if(counting==1){ self.parent.value4="animating" var position = firstResult.position let currentMatrix = self.modelentitydown!.transform.matrix let rotation = simd_float4x4(SCNMatrix4MakeRotation( 90.0 * .pi/180, 0,1,0)) let transform = simd_mul(currentMatrix, rotation) print("added moving ...") self.modelentity2!.move(to: transform, relativeTo: self.me, duration: 1, timingFunction: .linear) DispatchQueue.main.asyncAfter(deadline: .now() + 1.1) { counting=0 } } } } in my code, I firstly change rotation toward objective entity then move is there any way that I can do it more simply? (also wonder I hardcoded radian by 90 or -90 , any way to fix it by getting objective entity's position? )
1
0
1.6k
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.4k
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
610
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
412
Feb ’22