Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sprite Kit Collision without bouncing

I setup a hero and some platforms that are moving from the top downwards. With these I have collisionBitMasks that detect when the hero lands on a platform if the hero comes from above (to let the hero jump through the platforms)

if (_hero.physicsBody.velocity.dy > 0) {
                            _hero.physicsBody.collisionBitMask = 0;
                        }
                        else {_hero.physicsBody.collisionBitMask = platformCategory;
                                }

Everything works fine, except that the hero keeps bouncing on the platform. Is there a way to let him sit on it, while the platform is moving down?

I tried using physicsBody.resting and physicsBody.friction, but without any success.

Thanks for help Guys

like image 470
Elio_ Avatar asked Apr 04 '14 12:04

Elio_


1 Answers

Had the same issue just a minute ago. It works with setting the restitution but you need to set both restitutions. The one of the hero AND the one of the platform (or in my case the scene boundaries).

so:

hero.physicsBody.collisionBitMask = platformCategory
hero.physicsBody.restitution = 0.0
platform.physicsBody.restitution = 0.0
any_other_object_that_should_still_bounce.physicsBody.restitution = 1.0

will do it. All other objects on the screen still bounce on the platform as long as you set their restitution > 0

like image 104
jboi Avatar answered Nov 14 '22 22:11

jboi