简体   繁体   中英

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

You can set velocity directly:

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

Just set the vx the same as the moving object.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM