对于我的项目,我需要能够拍摄一个物体并让它完全停在它首先撞到墙壁的位置。我正在使用一个skaction沿着我点击的方向移动它并且确实接触以找到它与墙壁碰撞的时间,但是在它注册碰撞之前它经常开始穿过墙壁。
以下是我的拍摄方式:
var offset: CGPoint = rwSub(location, b: player.position);
var direction = rwNormalize(offset);
var shootAmount = rwMult(direction, b: 1000);
var realDest = rwAdd(shootAmount, b: player.position);
var velocity = 480.0/1.0;
var realMoveDuration = Double(self.frame.size.width) / velocity;
var actionMove:SKAction = SKAction.moveTo(realDest, duration: realMoveDuration)
println("\(realDest)")
firstFormed = true
portal1.runAction(actionMove)
这里是射弹的物理主体:
body.affectedByGravity = false
body.categoryBitMask = firstPort
body.collisionBitMask = wallCategory
body.contactTestBitMask = wallCategory
body.usesPreciseCollisionDetection = true
body.allowsRotation = false
body.restitution = 1
self.physicsBody = body
我需要获得射弹首先撞击物体的点,并确定它是对象的左下角,右下角,中间左角,中间右角,左上角还是右上角。现在它有时会撞到物体的底部,但是直到它通过物体的部分才会识别碰撞,导致它被添加到顶部。