Jackster
Jackster

Reputation: 41

How to make a moving sprite fall with physics in SpriteKit

I have a moving object that spawns object2 thats attached by a sliding joint

When i press the button , the joint is removed and the object2 falls down with gravity

this works, but only falls down on the x axis without retaining its y axis speed.

How can i make Object2 fall down in a more horizontal way like in real life

Scene Example

Upvotes: 1

Views: 521

Answers (2)

user4085203
user4085203

Reputation:

use after the remove of the joint

object2.physicsBody?.velocity = object1.physicsBody.velocity
object2.physicsBody?.affectedByGravity = true

if you use moveToY take a look at this question

Upvotes: 0

Valar Morghulis
Valar Morghulis

Reputation: 687

You can set velocity directly:

sprite.physicsBody?.velocity = CGVectorMake(10.0,10.0)

Just set the vx the same as the moving object.

Upvotes: 1

Related Questions