0
누구나 내가이 같은 노드에 충동을 적용하려고 할 때 왜 말할 수 있습니까?사용자가 스 와이프하여 SKSpriteNode에 충동을 적용하십시오.
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch:UITouch = touches.first! as UITouch
startPoint = touch.location(in: view)
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
defer {
startPoint = nil
}
guard touches.count == 1, let startPoint = startPoint else {
return
}
if let touch = touches.first {
let endPoint = touch.location(in: view)
//Calculate your vector from the delta and what not here
direction = CGVector(dx: endPoint.x - startPoint.x, dy: endPoint.y - startPoint.y)
L1Ball.physicsBody?.applyImpulse(CGVector(dx: direction.dx.hashValue, dy: direction.dy.hashValue))
}
}
나는 hashValue를 사용하는 것과 관련이 있다고 생각합니다. 나는 CGVector 방향에서 값을 얻는 또 다른 방법을 모른다. 방향 벡터를 임펄스 벡터로 사용하려고하면 충돌합니다. 어떤 통찰력? 감사!
네, 괜찮습니다. hashValue를 잘못 사용했습니다. 나는 이것과 스프라이트가 더 현실적으로 움직 이도록 편집했습니다. 벡터 크기를 줄이기 위해 필요합니다. ? (: impulseDirectionX, DY : impulseDirectionY) CGVector (DX) self.L1Ball.physicsBody impulseDirectionX = (direction.dx/4) 하게 impulseDirectionY = (-direction.dy/4) self.L1Ball.physicsBody .applyImpulse하자 ? .affectedByGravity = true – Lyres
좋습니다. 나는 당신의 질문에 정확하게 대답 했습니까? – Ralph
정말 고마워! – Lyres