1

Ok, trying to understand how to do this - I have a character (SCNNode) and need to determine if where the player is about to move (walking forwards) if there is no platform to hold him up (player affected by gravity).

If there isn't I am going to spawn a platform in place. What Ive thought to do is make a physics body just in front of character with different collision mask and check if did end contact with the platform physics bodies -

Like this:

enter image description here

Then checking name to see if area in front of character is empty, to know to spawn a platform:

func physicsWorld(_ world: SCNPhysicsWorld, didEnd contact: SCNPhysicsContact) {

        //Platforms
        if contact.nodeA.physicsBody!.categoryBitMask == Bitmask.collision.rawValue {

            if(contact.nodeA.name == bot.frontCollider.name || contact.nodeB.name == bot.frontCollider.name)
            {
                print("Front collide exit")
            }
            contactPlatform(contact.nodeA, touching: false)
        }
        if contact.nodeB.physicsBody!.categoryBitMask == Bitmask.collision.rawValue {

            if(contact.nodeA.name == bot.frontCollider.name || contact.nodeB.name == bot.frontCollider.name)
            {
                print("Front collide exit")
            }

Problem is this is causing other collision issues/not reliable. I don't think didEnd contact: SCNPhysicsContact) is the right way to do this - what would be the best way to detect if there exists a physics body right in front of where character, facing forwards?

blue
  • 7,175
  • 16
  • 81
  • 179

0 Answers0