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? )