SKFieldNode magneticNode attracting forces
Asked Answered
B

2

7

I am currently working with the iOS 8 SpriteKit API's and am having a hard time creating an attractive magnetic force with SKFieldNode. I can create an opposing magnetic force just fine, however I can't reverse the field. Heres what I have currently:

    touchField = [SKFieldNode magneticField];

    touchField.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:(self.frame.size.height/4 - 34)];

    touchField.physicsBody.charge = 3;

This particular field is supposed to be interactive with another SKSpriteNode.

Beading answered 5/7, 2014 at 6:38 Comment(0)
C
7

Electric and Magnetic fields are currently broken, as of iOS 8.1. They don't interact with the physics simulation at all.

What's probably causing your other node to move is that its physics body is inside the body you've attached to your field, which the simulation corrects by moving the nodes apart.

Also of note is that if magnetic fields were working properly, you don't need to add a physics body to it - the field node itself is intended to be enough to get the effect.

I've got an open bug report filed with Apple. Filing duplicates increases a bug's priority, so if you file one, mention that it's a duplicate of bug 18785194.

UPDATE: This bug still exists in iOS 8.3/Xcode 6.3 beta 2. I've received a request for more information on my bug report, so at least somebody at Apple is aware of it, but that was four beta versions ago.

UPDATE 2: This bug is partially resolved with iOS 9.0/Xcode 7.0 beta 2. Electric and magnetic fields now work, but custom fields are still broken.

Chrotoem answered 12/11, 2014 at 17:27 Comment(4)
Glad I found this; I was going crazy. Sometimes I wonder if they test things before releasing them. I'm not having any luck with customFieldWithEvaluationBlock either.Dispirit
customFieldWithEvaluationBlock: is also broken. My bug report mentions this as wellChrotoem
Are electric and magnetic fields still broken in iOS 8.2 and 8.3?Mon
@Mon Yes, they are. I've added a status update to my answer.Chrotoem
S
0
touchField.strength = -1;  

This line will reverse your field.

Septate answered 29/10, 2014 at 1:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.