Testing out my flash based iOS billiard game:
https://www.dropbox.com/s/hinx2j67xzq3ovs/poolX.jpg
I discovered that the white ball sometimes simply goes through the other balls,
while it collides with the other.
Is there a setting I miss?
I set the white ball body to awake before applying SetLinearVelocity().
Do other bodies need to be set awake or what?
Mirza
Try to use isBullet=true property on your ball body. (not proper collision in box2d)
Related
I would like to try and make a game similar to Altos Adventure. I am having trouble starting.
How to set up the terrain so that my character doesnt get stuck?
I simply drew a test sprite for the ground in photoshop. What collider2d should I use?
I use polygon collider and reduce friction in the material. But the character gets stuck, hits small invisible bumbs and it feels awful. The worst part is connecting 2 ground sprites together! The point where they connect is always messy.
I have a question for the future as well. How would I add the endless part of the game?
Would having many "pieces" set up and just spawning them as the player rides down work?
I havent written any code yet as the problem is simply in the physics in my opinion.
Thanks to anyone who takes the time and tries to help!
To move your player use rigid body.AddForce(Vector3 direction, ForceMode forceMode); then create a Physics Material with friction = 0 and put it in your player's collider.
I am new to SpriteKit and am trying to learn by creating a game similar to the popular iOS game Snake vs Block
(game screenshot
).
I am not sure if I am setting up the game's physics the most efficiently.
I set the blocks to be affected by gravity, while the ball node is not.
In the touchesMoved method, I set the ball node's position to the touch's x position (y never changes).
Once a collision is detected, gravity is set to zero vector, the leading ball is removed and last ball put in its place.
Once the block is removed, I restore gravity.
However I am not sure how to keep several ball nodes connected to each other as in the game and make them follow the lead ball's position with lag.
Any advice on this?
You can connect them together as joints via SKPhysicsJointPin. You are basically making a rope / chain, and there are a ton of examples for Box2d ropes (SpriteKit physics is Box2d).
Just add the latest ball as a pin-joint to the bottom:
Here are some references for you in addition to my answer:
convert objC to swift (more or less):
https://objectivec2swift.com/#/home/converter/
(Github to project in link ): https://www.youtube.com/watch?v=7jWdcbmnmKQ
http://www.waveworks.de/howto-make-hanging-chains-sprite-kit-physics-joints/
https://developer.apple.com/documentation/spritekit/skphysicsjoint
I am trying to make a brick breaking game with SpriteKit in Swift. To make the paddle I am trying to make it so that there are two SKPhysicBody, one for each half. To control the angle of which the ball bounces off the paddle, I want to rotate the physics body. I tried to use applyAngularImpulse or just applyForce, but they did not work. Is there a way to rotate the physics body??
You can't set the rotation of a physics body. You can however set the rotation of the node that the physics body is attached to. So what you can do is make a dedicated node for your physics body. This node will be invisible, it will only exist for you to rotate.
I have a particle emitter and I would like to detect it when the particles collide some physics bodies.
Is there a native way to do that in the SpriteKit API or do I need "to cheat" ?
Individual particles can not collide. Not with physics, not any other way. You do not even get any information about an individual particle - you can't access it's position, rotation, velocity .. nothing.
If you wanted to "cheat" you'd have to emulate the particle emitter using sprites, and animate the sprites with actions or manually. However keep in mind that this is much less efficient than a particle emitter.
In addition, if we're talking "particles" which often means dozens or even hundreds of them on screen, the amount of physics processing and collision detection quickly becomes prohibitively expensive if you were to model them using sprites with physics bodies attached. Do a performance test before you go down this path.
Particles do not have physics bodies, so they don't collide with Sprite Kit's physics engine
You can set the physics body of the particle emitter the same way you set it for any sprite node. Then you can set the category bit mask property and the contact test bit mask. The method didBeganContact can detect the collision afterwards.
didBegan contact is called whenever two bodies contact each other . Here is the apple reference link for how this method works:
Click [here](https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKPhysicsContactDelegate_Ref/Reference/Reference.html#//apple_ref/occ/intfm/SKPhysicsContactDelegate/didBeginContact:"Apple iOS developer library")!
I have this classic situation of a pinball game
All objects are physicsBody with rights collision masks and so on.. they collide perfectly.
The problem is that they only work when they are static...If I try to rotate a paddle on its anchorpoint, there is no collision with the ball and the ball falls down, passing through the paddle.
I thought it was a problem of speed but I think that during the rotation the physicsBody simply doesn't work.
Do you have suggestions?
Thank you so much.
That's exactly the problem you get when rotating a static body, it's not going to act physically correct.
For example static bodies have no force, no velocity - if you move or rotate it, it will just be there at the new position and new rotation without pushing any dynamic bodies around. Only if a dynamic body now happens to be intersecting with the static body will the physics engine try to resolve the collision, usually in a brute-force manner (aka "get me outta here").
Therefore the paddle has to be dynamic if you want it to move, accelerate and spin the ball. Both paddle and ball may need to have continuous collision detection enabled as to not lose any precision in the paddle motion applied to the ball, and vice versa.