Home > other >  Swift UIKit dynamics - Vary UIPushBehavior force magnitude by distance from center of source
Swift UIKit dynamics - Vary UIPushBehavior force magnitude by distance from center of source

Time:04-17

Can someone suggest how I can vary the UIPushBehavior magnitude force by distance from source. To mirror the affect of the force of wind from a fan on another object. So the closer the object is to the fan the stronger the force.

if String(describing: identifier) == "fan1" {
                self.push = UIPushBehavior(items: [self.object], mode: .instantaneous)
                self.push.setAngle(.pi/4, magnitude: 1)
                self.animator.addBehavior(self.push)
                self.push.addItem(self.object)
                
            }

CodePudding user response:

Use a enter image description here

That feels like a fan on the bottom left to me!

You can also choose a radial gravitational field positioned at where the fan is, if your fan is in a corner and blows "radially", but note that you should use a negative value for strength in that case to say that the field repels rather than attracts.

  • Related