On IOS7.1, using SpriteKit, I've created two simple rectangular sprites with corresponding physics bodies. I set up contact and collision bit masks, and all works exactly as I expect: contacts are detected and collisions prevent the two rectangles from overlapping. But when I create an SKPhysicsJointSpring object and join the two rectangles, no contacts are ever detected even though the rectangles sometimes overlap during simulation. (The spring behavior works just as one would expect, though, with visible oscillations.)
In other words, joining physics bodies seems to prevent contact detection and collisions in SprikeKit, which is not the behavior I desire.
Anyone know of any way to fix this? Thanks.
There is no fix, this is built-in behavior of the Box2D physics engine Sprite Kit uses. When you connect two bodies through a joint, they no longer contact and do not collide with each other.
With Box2D you can change this behavior via the collideConnected flag. However no such flag exists in Sprite Kit's physics classes.
Related
I've recently played Nintendo Badge Arcade and I wondered how is the clamp implemented.
The expected behavior, for those who don't know the game can be seen in this video:
http://ytcropper.com/cropped/2-59b6b68872036
I know the items the player can obtain follow the basic physics of any game engine (they have their gravity, their weight, and its shape is related to its sprite) but I don't know how to implement the clamp.
My first question is: What is the ideal game framework to achieve this. Game maker, box 2d...
And my second and most important question is: How is the clamp implemented. Is it a composite object that rotates both bodies until they touch something and then friction comes in?
Thank you.
One way to go is use Box2D and its Revolute joint to simulate a clamp. Basically clamp is 3 dynamic bodies: hull, and two side bodies that are marked as "ghost" for the hull (so that they do not collide). Joints connecting those bodies to hull must be configured to rotate in the right direction and only when a player performs an action. When a prize is hit by clamp you keep them joints working for body not to fall down thanks to mentioned friction.
More detailed information can be found in box2d tutorials, I hope the idea is clear.
Is it possible to have a physics object in GameMaker Studio use precise collisions?
Here's some context for my question. I'm making a pirate game where the player sails around a large ocean with a number of islands. I've been using the physics engine to control the movement of the ship, and that is working well. However, the problem arises when trying to introduce collisions between the ship and the various islands. As far as I can tell, the underlying physics fixtures can only be formed into fairly simple shapes. Specifically, the collision shape editor is limited to 12 points, and only convex shapes. This is a problem, because many of my islands are relatively complicated non-convex shapes, and aren't necessarily a single piece. It would be nice to be able to use the island sprite as a precise collision mask, as would be possible for non physics based objects.
Is there a way to do this, or a possible work-around that I'm missing? Here's an example of one of my islands:
I can see two solutions to your problem.
1 - The easiest, but performance-unfriendly.
In the sprite editor, click "Modify mask". There should be a "precise collision checking" box you can tick. This means that your sprite will be checked pixel by pixel for collisions. As you can guess, this is not performance friendly, but will do exactly what you want.
2 - The one I would recommend.
What you could do is just draw the island sprites, either through the background or via a dedicated object, and then create some simple shape objects (rectangle, circle and diamond), that would be invisible, and place them over your islands in the room editor. (Don't forget that you can stretch them).
These simple shaped objects would be the ones to check for collisions.
I used this technique make a hitbox for complex-shaped clouds in one of my games, so I know it works.
I believe that the island you show us can be fairly well covered with a few ovals and a long rectangle.
Bonus : after doing that graphically, you can copy the creation code of the shapes from the room create event to the island create event to repeat for multiple identical islands. Just don't forget the position/angle offset !
By using the Shape options when defining the collision shape, you can have any kind of Convex polygon as your collision shape. Example:
The spot where you choose the Shape option is in red.
After you select that option, you can just click & drag to add/edit a vertex to the polygon. Just bear in mind, it has to be a convex polygon, GameMaker is very strict about that. You can also remove vertices by right clicking on them.
Is it possible to add two (ore more) SKPhysicsBodys to one SKNode? Something similar to this:
Example from PhysicsEditor
Because the head of the character should collide with a ball, the top should be round. Furthermore the ball mustn't go through the player. Do you have an idea how to accomplish this?
As the physicsBody property on SKNode suggests, there's a one-to-one relationship between nodes and physics bodies.
However, that doesn't mean you have to have one basic shape for every visible sprite. There are a few approaches you can take to accomplish what you're looking for:
Does the top really need to be rounded? You can cover most of the monkey art with a rectangle. (I presume you want a rounded top so collisions bounce in different directions, though.)
Create the "round-ended-rectangle" shape you're after using a polygon. You'll have to pick a number of sides for approximating the curve that fits your app: too many and it'll slow down the physics simulation, too few and it won't behave like a circle when other bodies bounce off.
Every body needs a node, but not every node needs a visible sprite. You can make your monkey out of two nodes: one that holds the art and has the square or round physics body attached, and another node that has the other physics body, attached through a fixed joint,
but with no art.
This is the top hit on Google for this question so i thought I'd update the answers. This is possible (Although may not have been in 2013), as per the answer from Mike S in this post.
You need to use
// Swift
SKPhysicsBody(bodies: <#[AnyObject]#>)
// Obj-c
[SKPhysicsBody bodyWithBodies:(NSArray *)bodies]
So you create a body with other bodies and add that one body to your SKnode.
No, every SKNode can only have one SKPhysicsBody since physicsBody is a single property of SKNode. Like rickster said, your first option is to make the monkey one silo-shaped physics body using the bodyWithEdgeLoopFromRect: class method of SKPhysicsBody.
Your other option is to create two separate SKNodes and attach them with an SKPhysicsJointFixed. rickster's answer is great, but I just wanted to give the class names in case you want to do a little Googling around.
I am working with kinect in openframework using the ofxKinect addon, which is great and plenty fun!
Anyway I am looking for some pointers or a direction when dealing with multiple bodies on the screen. I was thinking of making a rect around each detected body and when the rects intersect something could happen, an effect or anything.
So what I am looking for are ideas or something that could point me to the right direction of detecting multiple bodies when using a kinect.
Right now based on the depth image I get from the kinect I go through each pixel and create a bunch of smaller rectangles with a padding and group them in a larger rectangle bound if they are separate from another rectangle group. This is not ideal as it only deals with the pixel values and is not really seperating bodies from eachother and is not giving me the results I am looking for.
So any ideas would be greatly appreciated!
If you want to use ofxKinect a quick solution would be to threshold on depth and assume bodies and no other objects will be within a depth range. This should make it easy to use the OpenCV's contour finder to isolate the outlines of the bodies and get the bounding rectangles. If the rectangles intersect(and ofRectangle already does the math you), trigger the reaction you need. Also don't forget to do that once if the effect isn't showing already, otherwise you will trigger the effect multiple times per second while the two bodies' bounding rectangles intersect.
You could try something a bit more hardcore and using ofxCv(not just ofxOpenCV) to tap into the HoG functionality. This is slow in itself and not ideal with the depth map, but hopefully you can run in every few seconds just to detect a person and the depth, then keep tracking that movement.
Personally, if you want to track people with the Kinect I recommend using ofxOpenNI as if already provides the scene segmentation feature and even if you don't track the skeletons you can still get useful information like the pixels pertaining to each body and they're centre of mass. I'm guessing Microsoft KinectSDK has a similar feature and there should be an oF addon, but it's windows only.
ofxKinect/libfreenect does not offer any people detection features, so you will need to roll your own.
I've just got started with physics. I'm using Java, though language does not matter obviously. Now I though I'd do something like this:
A ball with a certain speed, radius and mass hits a rectangle with a certain mass, width and height. Depending on where the ball hits the rectangle (how high up), and all the properties the ball and the rectangle have that i just mentioned, there will be different outcomes of the situation.
These are the four possible outcomes:
The ball bounces back because the rectangle was too heavy
The rectangle starts to wobble, but then goes back to normal
The rectangle falls to the right
The ball strikes through making the rectangle fall to the left
Please note, I don't expect you to write a program for me. I understand it is a lot to think off. But I have no idea how to start. I would really appreciated some guide lines and links to further reading about this (I was not sure what to google to find info about this.)
And also, I'm doing this to learn, so don't tell me to use an engine or anything like that.
You are trying to build a simple physics simulator. This is a pretty involved problem, and you'll have to learn a certain amount of physics along the way.
I suggest you develop the simulator to handle these situations, roughly in this order:
An object moves through space (constant velocity, no gravity).
An object moves under the influence of a constant force (such as gravity).
An object moves with a constraint (e.g. a pendulum, a rolling square).
An object slides across a surface, with friction (both static and kinetic).
Two objects collide inelastically (they stick).
Two objects collide elastically (they bounce).
Once you have all of these, you will be able to simulate your ball and rectangle.