Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get contact events triggered? #8

Closed
pradeeproark opened this issue Sep 11, 2020 · 2 comments
Closed

How to get contact events triggered? #8

pradeeproark opened this issue Sep 11, 2020 · 2 comments

Comments

@pradeeproark
Copy link
Contributor

pradeeproark commented Sep 11, 2020

Category: 'Behavior'

Describe the bug
didBegin and didEnd of PhysicsContactComponent not getting called.

To Reproduce
Steps to reproduce the behavior:

  1. Start with a new 'SwiftUI/tvOS' project
  2. Follow instructions in https://invadingoctopus.io/octopuskit/documentation/guide.html#physics-collisions to setup two components to collide/contact with each other.
  3. Add the following code:
final class BunnyContactComponent: PhysicsContactComponent {

     func didBegin(_ contact: SKPhysicsContact) {
        print("hungry bunny")
    }
    
    override func didEnd(_ contact: SKPhysicsContact, entityBody: SKPhysicsBody, opposingBody: SKPhysicsBody, scene: OKScene?) {
        print("hungry bunny")
    }
}
  1. Build for 'tvOS'
  2. Run and perform these actions: Try to move the bunny around with a PointerControlledPositioningComponent and let it collide with a collectible component ( a carrot sprite with a physics body)
  3. Bunny pushes the carrot around without triggering the contact event

Expected behavior
didBegin/didEnd Contact event in BunnyContactComponent should be called

Screenshots
ezgif-2-5f05a32234ce

Build Environment (what you're developing on)

  • OctopusKit Version: 'develop'
  • macOS Version: '10.15.6'
  • Xcode Version: 'Xcode-12 beta 6 (12A8189n)'
  • Swift Version: '5.3'

Target Device (what you're compiling for)

  • Device: 'AppleTV Simulator'
  • Target OS Version: 'tvOS'

Additional context
The scene has the following setup in createContents

self.entity?.addComponents([sharedMouseOrTouchEventComponent, sharedPointerEventComponent, PhysicsWorldComponent(), PhysicsComponent(physicsBody: SKPhysicsBody(edgeLoopFrom: self.frame))])
        
        
self.componentSystems.createSystem(forClass: BunnyContactComponent.self)
@pradeeproark
Copy link
Contributor Author

I see that I missed adding the sharedPhysicsEventComponent to self.entity in the scene. with that added it all works now.

@ShinryakuTako
Copy link
Member

ShinryakuTako commented Sep 13, 2020

When you use the same contact handler for multiple entities, you'll want to make sure to process each event for only one entity, otherwise you'll be printing "hungry bunny" twice!

That is, didBegin will get called for Entity A and Entity B.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants