简体   繁体   中英

Constantly change the direction of gravity to be where an object is randomly moving

I have an object that is randomly moving, and other objects are spawning next to it.

How can I change the gravity direction of the objects that are being spawned to make it so the spawned objects are always moving towards my randomly moving object?

In my didMoveToView I tried adding the following:

self.physicsWorld.gravity = CGVectorMake(costantlyMovingObject.position.x, constantlyMovingObject.position.y)

But this just causes the spawned objects to fly around like crazy

如果要将所有对象移向您的对象,则应使用SKFieldNode radialGravityField

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