难以获得碰撞点
trouble getting collision point
嘿,我正在尝试获取碰撞点,然后在该点为两个节点创建一个关节。我不确定我的结果意味着什么或如何得到我想要的。
我无法访问我在其他帖子中看到的联系点。碰撞中的 CCContactSet 只给我点数和正常值。
我在碰撞开始时输出法线及其 (1.0, -0.0) 左壁,(-0.0, 1.0) 底壁,(-1.0, 0.0) 右壁,(-0.0, -1.0 ) 顶墙。我基本上不了解他们。我知道他们只是指的是第二个 hullPiece,因为无论我在碰撞过程中如何旋转或定位助推器,结果都保持不变。只有当我旋转 hullPiece 时它们才会改变。
那么如何获取接触点来创建关节呢?我应该为此使用法线吗?如果是的话怎么办?
newSprite = CCSprite(imageNamed: "Booster.png")
newSprite.position = CGPoint(x: 200, y: 200)
newSprite.scale = 4.0
let spritePhysics = CCPhysicsBody(rect: newSprite.textureRect, cornerRadius: 0)
spritePhysics.collisionType = "booster"
spritePhysics.sensor = true
newSprite.physicsBody = spritePhysics
editorPhysics.addChild(newSprite)
newSprite2 = CCSprite(imageNamed: "HullPiece.png")
newSprite2.position = CGPoint(x: 200, y: 200)
newSprite2.scale = 4.0
let spritePhysics2 = CCPhysicsBody(rect: newSprite2.textureRect, cornerRadius: 0)
spritePhysics2.collisionType = "hull"
spritePhysics2.sensor = true
newSprite2.physicsBody = spritePhysics2
editorPhysics.addChild(newSprite2)
func ccPhysicsCollisionBegin(pair: CCPhysicsCollisionPair!, booster: CCNode!, hull: CCNode!) -> ObjCBool
{
NSLog("contact point\(pair.contacts.count) \(pair.contacts.normal)")
return true
}
您可以通过 CCPhysicsCollisionPair
的 contacts
属性 访问联系点。
contacts
结构如下所示:
typedef struct CCContactSet {
/// The number of contact points in the set.
/// The count will always be 1 or 2.
int count;
/// The normal of the contact points.
CGPoint normal;
/// The array of contact points.
struct {
/// The absolute position of the contact on the surface of each shape.
CGPoint pointA, pointB;
/// Penetration distance of the two shapes.
/// The value will always be negative.
CGFloat distance;
} points[2];
} CCContactSet;
通过points
数组,您可以访问每个相关形状的确切碰撞位置。
嘿,我正在尝试获取碰撞点,然后在该点为两个节点创建一个关节。我不确定我的结果意味着什么或如何得到我想要的。
我无法访问我在其他帖子中看到的联系点。碰撞中的 CCContactSet 只给我点数和正常值。
我在碰撞开始时输出法线及其 (1.0, -0.0) 左壁,(-0.0, 1.0) 底壁,(-1.0, 0.0) 右壁,(-0.0, -1.0 ) 顶墙。我基本上不了解他们。我知道他们只是指的是第二个 hullPiece,因为无论我在碰撞过程中如何旋转或定位助推器,结果都保持不变。只有当我旋转 hullPiece 时它们才会改变。
那么如何获取接触点来创建关节呢?我应该为此使用法线吗?如果是的话怎么办?
newSprite = CCSprite(imageNamed: "Booster.png")
newSprite.position = CGPoint(x: 200, y: 200)
newSprite.scale = 4.0
let spritePhysics = CCPhysicsBody(rect: newSprite.textureRect, cornerRadius: 0)
spritePhysics.collisionType = "booster"
spritePhysics.sensor = true
newSprite.physicsBody = spritePhysics
editorPhysics.addChild(newSprite)
newSprite2 = CCSprite(imageNamed: "HullPiece.png")
newSprite2.position = CGPoint(x: 200, y: 200)
newSprite2.scale = 4.0
let spritePhysics2 = CCPhysicsBody(rect: newSprite2.textureRect, cornerRadius: 0)
spritePhysics2.collisionType = "hull"
spritePhysics2.sensor = true
newSprite2.physicsBody = spritePhysics2
editorPhysics.addChild(newSprite2)
func ccPhysicsCollisionBegin(pair: CCPhysicsCollisionPair!, booster: CCNode!, hull: CCNode!) -> ObjCBool
{
NSLog("contact point\(pair.contacts.count) \(pair.contacts.normal)")
return true
}
您可以通过 CCPhysicsCollisionPair
的 contacts
属性 访问联系点。
contacts
结构如下所示:
typedef struct CCContactSet {
/// The number of contact points in the set.
/// The count will always be 1 or 2.
int count;
/// The normal of the contact points.
CGPoint normal;
/// The array of contact points.
struct {
/// The absolute position of the contact on the surface of each shape.
CGPoint pointA, pointB;
/// Penetration distance of the two shapes.
/// The value will always be negative.
CGFloat distance;
} points[2];
} CCContactSet;
通过points
数组,您可以访问每个相关形状的确切碰撞位置。