I am trying to implement wave effect when any thing hits the hanging object, how can I achieve the both,:
1.Hang an object in air(as it will be a dynamic body which will wave)
2.implement waving effect on that body
Thank You
The answer isn't in cocos2d but in your physics engine, if you are using box2d check the distance joint. not sure on chipmunk.
in testbed example see the chain example.
u can create no of small boxes and joint them looks like rope.
but be careful while specify the anchorpoint.
Related
I m wondering that if is it possible to animate anything along the rules of physics.
I mean, i have a cube, and two legs attached to that cube. I want to just animate that legs one after each other, but unity or other software will force its animation system to behave to my animated legs to make my cube walk. I wont change positions for my body(cube) but legs will do that.
demonstration:
https://streamable.com/dda610
Yes, this animation type is called procedural animation. You base your animations dynamically based on physics.
https://en.wikipedia.org/wiki/Procedural_animation
good video:
https://www.youtube.com/watch?v=LNidsMesxSE
tutorial:
https://www.youtube.com/watch?v=9Wh6fzSl_u8
Physically based animation is a complex task. You can use the timeline to animate legs but they won't work too well physically. You probably want to use code to keep the body a fixed height above the surface and use the timeline editor to animate the legs. Or perhaps keep the body at the same height and use 'inverse kinematics' to move the legs in a more realistic fashion. Neither of these options will be very quick for you to start using really effectively if you have very little experience with unity or with code but knowing what to look up is half the battle of learning.
I am creating a 2D game and I want to implement two game objects with circular colliders to detect collisions following say an object is travelling from Point A to Point B then -
See the image for details
Thanks for the help
I think the easiest answer is to just make a polygon collider 2D that looks like a ring, like so but without the gap and much thinner:
Then you can use OnTriggerStay2D to run the code you'd like to run on collision.
As the title says, I'm trying to find a way to implement a kind of floating bubble (a SKSpriteNode object) inside my game.
I'm using SpriteKitbut I really don't know which is the best way to approach this problem. In particular:
Should I "play" with values inside Xcode Physic Body in order to find good stats which reflects the physic of a soap bubble?
Or I should change the gravity to 0.0 and handle the animations through code? If so, what if I need to implement other objects who need to be affected by the standard -9,8 gravity value?
If i understood what you are thinking....a good idea would be using a Particle Emitter, there you can use a texture and play with lots of options. There you can have lots of bubble, emit them.
If your idea is just animate one or two bubbles....then you may do this with spritekit code (gravity to 0.0), using SKAction to move the bubbles, fade in/out or just play with .alpha.
You can also use gravity to move it...but you will have less control about what bubble is doing...
If you need more help just comment this. Hope i helped you!
In cocos2d, i've got two objects that I want to detect collision with.
Im using CGrectintersectsrect, which has been working fine thus far.
But I want to divide up the bounding box of one of my objects into 4 quarters, so that if my object collides in any one of these quarters, appropriate physics can then be applied.
At the moment, there is only 1 large boundingBox which is insufficient. Ideally I would want 4+...
Is this possible, and if so how could i achieve this?
If not, is there any other avenue that could work?
Thanks everyone, once again :)
The boundingbox method returns a CGRect. You have to divide your rect manualy, there is no pre-made method for that.
Otherwise if there is a lot of objects, the best way to detect the collisions is to use Box2d. You can follow this tuto to see
How To Use Box2D For Just Collision Detection with Cocos2D iPhone tutorial.
Hello everyone I an very new to cocos2d, so I apologize if this is a simple question. I would like to create to sprites that collide when they hit each other.
For instance, one sprite, spriteA, is in a fixed position on the screen. And another sprite, spriteB, is moving around the screen. SpriteB will collide with spriteA. If that doesn't make sense or you don't understand it, tell me and I will elaborate further. Any help is appreciated. Thank YOU!
Try using Chipmunk or Box2d physics systems. These are included with Cocos2d and work by having a physics simulation that updates with every time the graphics change on screen.
The physics simulation will tell you if two objects are overlapping, and will provide physical attributes like weight, slipperiness (friction), speed and direction, which creates reactions like bouncing, sliding, realistic loss of speed and changes of direction on impact.
If you are new to physics simulation, here's a 30 second run down:
Create "bodies" in the physics simulation that represent each graphical sprite
Bodies are usually defined more simply than their graphical counterparts, like a circle, square or simple polygon shape
In order to update the graphics on the screen accurately, first you establish a pixels to meters ratio. Meters are notional (i.e. made up) measurement that is used in the physics sim
Each time the physics simulation "ticks", you update the graphics on screen accordingly
So if a body in the physics sim moves 1 meter, you might transform the pixel sprite 32 pixels
Here's a good tute on collision detection using Box2d.
http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone
enjoy
Its actually very simple:
Just schedule a timer: [self schedule:#selector(checkForCollision:)];
Specify the method: - (void)checkForCollision:(ccTime)dt {}
In the curly braces, make CGRects for each sprite using CGRectMake.
Then in the same method, just call: if (CGRectIntersectsRect) {}
That easy!
Well technically speaking when the 2 sprites interact, or share at least one common point, then they are colliding. I'm a little confused by your question. Are you asking for direction on how to make the sprite move on screen, or are you asking how to handle the actual collision(such as calling a method if they collide)?