Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
SpriteKit wrapper
-
@JonB, thanks for checking the code. Falloff 100 was just last of a series of trying different values, but even with falloff 0, the result I see is the same: strength 0.002 looks like no field at all, strength 0.003 is completely overpowered.
I thought I might wait and see if iOS 13 brings any change to this.
-
Do you set the mass of your space ship? Also, have you played with region /minimum radius?
-
This is becoming even more awesome ! Congrats @mikael for those wonderful spiral effects ! Do you think you should be able to make a 2D light system ?
Cordially,
SmartGoat -
@mikael I think you wanted a radial_gravity field instead of vortex. At least that’s what you simulated. Vortex forces are along the tangent direction, instead of radial. What you might want is a co-located vortex and radial gravity, to create a sort of whirlpool.
The vortex_field.node.minimumRadius also prevents the field from blowing up at the center if you use a positive falloff.
-
class LightNode(Node): enabled = node_relay('enabled') ambient_color = node_relay('ambientColor') light_color = node_relay('lightColor') shadow_color = node_relay('shadowColor') falloff = node_relay('falloff') category_bitmask = node_relay('category_bitmask') def __init__(self, **kwargs): self.node = SKLightNode.node() super().__init__(**kwargs)
And following added to SpriteNode def
lighting_bitmask = node_relay('lightingBitMask') shadowed_bitmask = node_relay('shadowedBitMask') shadow_cast_bitmask = node_relay('shadowCastBitMask')
Which allows one to do
ship.lighting_bitmask=1 ship.shadow_cast_bitmask=1 L=LightNode(parent=scene, position=(270,500)) L.falloff=2 L.category_bitmask=1 L.z_position=100 L.ambient_color=UIColor.redColor() texture=SKTexture.textureVectorNoiseWithSmoothness_size_(.5,CGSize(1400,1400)) n=texture.textureByGeneratingNormalMap() bg=SKSpriteNode.spriteNodeWithTexture_normalMap_(texture,n) bg.lightingBitMask=1 bg.shadowedBitMask=1 scene.node.addChild_(bg) bg.zPosition=-10
-
- I have set range, which seems to work fine
- I have not set minimum distance, as the default is a very small value, and not an issue yet
- I tried playing with density, but it does not have an impact as vortex sets the velocity regardless of mass
- I am sure I want the tangential ”flinging away” vortex field instead of the radialGravity (which would be more like the gravity of a black hole, planning on adding that later)
-
Your simulated vortex is really a radial_gravity.
Vortex field applies a force, not a constant velocity. I think your mass was like 0.03 or something like that. I suspect the physics engine is using singles, in which case really teeny mass any really teeny forces combined with high velocity might not be numerically stable.
If you bump up ship mass, to 1, strength of near 1 behaves better, though you'd have to increase the thrust, etc otherwise you can't move the rocket. Maybe a colocated drag field could also help with things going crazy, though I didn't try that yet. Another thought I had but have not tried is two fields with different region, one with negative strength, so you get a sort of narrow annular ring of force, which prevents things from accelerating really high.
-
@SmartGoat, now the version on GitHub has LightNode support similar to @jonb's example:
Lower rock uses the default normal map for a moderate but not bad shading effect:
rock = SpriteNode( 'spc:MeteorGrayBig3', lighting_bitmask=1, parent=scene) light = LightNode( category_bitmask=1, light_color='white', falloff=1.2, position=(50,100), parent=scene )
The upper rock has a normal map where I upped the contrast so that there's some clear ridges:
rock_too = SpriteNode( 'spc:MeteorGrayBig3', normal_texture=Texture('spc:MeteorGrayBig3').normal_map(contrast=10), lighting_bitmask=1, position=(100,200), parent=scene, )
Textures have a
normal_map
method that has the optionalsmoothness
(default 0.0) andcontrast
(default 1.0) parameters.Texture class also has a
noise_vector_map
method, with a required size parameter and optionalsmoothness
(default 0.0). This returns a random normal field, like the one @jonb used in his example. -
@JonB, thank you for your tenacity.
On the topic of the vortex field, I stand firm. As the doc says: ”The physics body is accelerated along the perpendicular of the line between the field node’s position and the position of the physics body.”
On the topic of the low mass of the ship being the problem, you were right (again). After setting the ship’s density to 100, which brought its mass above 1.0, the field behaves sanely and field strength of 1 turns out to be just about right for my purposes.
Thank you!
-
The physics body is accelerated along the perpendicular of the line between the field node’s position and the position of the physics body.”
Right this is saying the force lines travel in circles around the node (tangential, instead of radial). If you debug_fields, that is clear.
You said the vortex applies a velocity, which is one thing I was disputing -- it applies force. (Force=mass*acceleration, so it also could be said to produce a mass dependant acceleration). But it does not produce a velocity, directly anyway.
(There is a spritekit velocity field, iirc, which does enforce a constant velocity, based on the texture. That's more for thinks like things floating in a river, or conveyor belt, etc-- though you could create a custom texture that acted like a tangential velocity field... But I'm not sure how that behaves with other physics -- if the velocity is enforced rather than acting like a drag or friction, it seems like things in the field are at the mercy of the field)
The other thing I was saying is that simulate_vortex is actually simulating radial gravity... But I was wrong -- I didn't see the
v.radians += math.pi/2
line, so I misread that you were applying the force along the direction to the bouy not perpendicular to it. Sorry for the confusion! -
@JonB, yes, I misread/misremembered the acceleration as velocity, and also forgot some of my basic physics as well, and really should have taken the time to go back to the docs after your first message, sorry.
In any case, I am super happy to have this clarified, both in order to avoid similar confusion with fields in the future, as well as to avoid any extra Python code in the update.