I'm trying to set up some elastic collisions using Sprite Kit. There is an issue with the case of multiple objects resting near each other as I asked in Sprite Kit Physics Collision Issue
I am confused on the timing of the situation for a collision.
I've tried to set dynamic
to NO
in -didBeginContact:
delegate method, calculate final speeds, then in -didEndContact:
set dynamic
to YES
and then set the velocities correctly.
The reason I want it to be dynamic outside of the collision is because I want friction/gravity etc to be available. What is wrong with the order/logic? I looked at -didSimulatePhysics
method, but it didn't seem like the way to go.
I'm trying to set up some elastic collisions using Sprite Kit
I think you're misunderstanding the physics in play here. An elastic collision is an oversimplification of a collision. In reality, no collision results in a perfect transfer of energy. I've explained the physics here in an answer to the related question you linked to.
I suspect reading through that you will see that an "elastic" collision can be done in SpriteKit, but most people don't realize you need space between the objects. You shouldn't need to do your own physics calculations.
I'm not sure if this is exactly what you are trying to do, but if I wanted to compute results of collisions without the help of SpriteKit while leaving all other physics to SpriteKit, I would do the following:
dynamic
property always set to YES
. categoryBitMask
property for each kind of object.collisionBitMask
property for an object to the disjunction of all categoryBitMasks for which you want to retain automatic collision calculations (e.g., walls, but not other objects), or just to zero, if you want to handle all collisions manually.contactTestBitMask
property for an object to anything for which you want to calculate collisions manually.didBeginContact
.(In short, exclude your objects from their own collisionBitMask
.)
This link might be helpful: Working with Collisions and Contacts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With