Box2D and Sand in AS3 - actionscript-3

I want to create a game where you shoot a rocket into the ground (Sand) and it blows, and moves the sand to the sides...
Is it possible in Box2D? breakable little objects?
It's almost pixel perfect collusion detection.
Thanks!

Yes it's possible, but beware your performance is going to be pretty weak. See the following articles (sorry guys, I normally like to paste in code instead of just link but there is are too much of it).
http://www.emanueleferonato.com/2012/01/17/create-real-explosions-with-box2d-adding-textures/
http://www.emanueleferonato.com/2012/01/05/create-real-explosions-with-box2d-exploding-objects-and-setting-the-center-of-explosion-with-mouse-click/
http://www.emanueleferonato.com/2011/12/08/create-real-explosions-with-box2d/
As far as dirt flying out when the ground breaks, the dirt doesn't have to be physical, you can just fake that with some particle effects. (Lots of tutorials on those things here)

In box2d it's not possible to break an object other than to remove the old one and create many new objects. If you need almost pixel perfect collision detection you'd need lots of objects. A 100x100 square contains 10 000 pixels.
A year ago I created a physical simulation involving many small particle-like objects using box2d. You can find the video here. The number of objects you see there is close to maximum Alchemy version of box2d could handle. AS3 version failed with much less.
You should google how it was done in old-school games like Scorched Earth for example. Or it might be possible to "cut" sand particles in area of effect of your missile from box2d shape, create many small particles, simulate them and join back to main terrain shape. But it sound very complicated.

Related

Bullet - Rigid bodies not colliding at high speed?

I'm trying to make a basic first person shooter game with Bullet and OpenGL. I'm having the issue of my rigid bodies not colliding at high speed.
My bullets will go straight through any other rigid bodies that I have, such as walls. Reducing velocity to less than 10 does result in collisions, but this is too low for a moving bullet. The bullet also moves insanely fast (I know it's a fast moving bullet, but sometimes I can't even see it, not sure if that's expected).
I'm thinking that it's to do with how I'm stepping the simulation? Reading up on it has left me confused. How can I make it so that my objects will always collide (at least, when going reasonably fast), and if possible, is there a way to slow the simulation down whilst maintaining the correct bullet velocity etc. so that I can actually see the bullet moving and colliding?
Here are some approaches to solve:-
It is copied from How can I avoid missing collisions for fast moving objects? - an official FAQ
smaller timesteps
extruding the object along the motion
ray cast to the new position
swept collision test (convex cast, linear cast)
continuous collision detection, including rotational motion
Please read the link for more detail. It is not a trivial issue.
One important thing to ask before try anything: do you really need high speed object?
It is not free (cost more CPU).
Here is another useful link (less useful though) : https://gamedev.stackexchange.com/questions/11961/how-can-i-enable-ccd-in-bullet-physics

Flash automatically finds curve intersection points. Can I use that code like I use curveTo in actionscript?

Or do I have to get down and dirty with the math and do the spline intersection math myself? I know the basic math for Quadratic b-splines.
I'm trying to make procedural randomly generated Celtic knot-work that animates itself. I'm inspired by the book of Kells original book -and the animation of the same name. This means at best it will be seriously complicated - lots of curves animating fast. I'm going for generative -responsive to the user- Celtic knots of the highest possible complexity.... that may mean only 12 points animating randomly and in response to mouse movements but... I'd love hundreds or tens of thousands... some day.
Developing a moving random curvy double lined loop scribble was easy. I like the look of the curves made from 12 to 14 random points. Now I want to weave it over under over under. To do that -- I need to find the intersections of lots of random curves quickly for each frame. When I draw curves in Flash in the -not object- drawing mode... Flash does intersections and generates points automatically for me.
Questions:
-Is there an equivalent intersection class/method/function in Actionscript 3.0 to the intersections so easily done in the flash drawing interface?
-How much of what you do in Flash as an artist has cool classes like curveTo in Actionscript 3.0?
-Can I see the source code for curveTo?
-Can I extend the curveTo to do what I want?
-I have been reading and re-reading the reference and how to extend classes... that I made. But how to I learn how to extend curveTo ... or Path classes... can I?
Would this be something that you are looking for:
http://actionsnippet.com/?p=965
See a demo here: http://www.actionsnippet.com/swfs/bezier_intersect.html

Making a Continuous Floor (Actionscript 3)

I'm making a game similar to 'Run' (http://www.albinoblacksheep.com/games/run) but I can't quite figure out the floor part. I'm not wanting the sides and a ceiling like in 'Run', just the main floor.
I'm new to Flash game development (AS3) but I know the basics. I realise the character isn't moving and is just turning (the level itself moves). How do a make a continuous floor, do I have to make a very long .fla file, or do I have to do this with code?
All ideas and help appreciated, Thanks. =)
You should use Tiles. Basically, a tile game consists of a lot of squared tiles, which are inserted when appear in screen and removed when goes out.
In your case, maybe you could use a big tile, with screen's size.
You can visualize a good example here, also a very good resource for gamedev on Flash.
You need to generate sprites of the edge of the screen and either recycle them when their x < some value or dispose and create new ones.
I think you can just use Bitmap.draw() to draw different pixels on a Bitmap that you've applied a 3D transformation to. You can see the basic concept illustrated here.

Collision and bounce detection from array of points

I have an array of points that I will use to generate a closed polygonal fence on the outside of a game stage (2D). I wish to have collision detection between this fence and a bouncing ball-like object on the inside.
Additionally, I would like to be able to arbitrarily add/remove/redraw the fence in realtime and have the collision detection still operate realistically.
I have considered drawing a Sprite/Shape from the points and doing a HitTest at each frame to check whether to bounce or not.
My question: is this the best/correct way to accomplish this goal? Consider something like JezzBall with diagonal lines of any angle a simulation of what I'm trying to do.
Check the corners of your bouncing ball with four hitTestPoints. If it succeeds, then do hitTestPoints from the fence with shapeflag set to true.
There may be better solutions as I do not know the performance impact of shapeflag, but combined with the corners optimization I think it will be good, but I'm also interested if there is a better way.
Math will be your friend here. Do a quick search for circle-line, or point-line collision (here's one: Circle line-segment collision detection algorithm?).
What you do is run through your array of points, creating lines. So line 1 will be points[0] and points[1], and line 2 will be points[1] and points[2]. After that you check each line against your ball (if you want proper collision that will work no matter the frame rate, then you create a ball line, which is the line that the ball has travelled along between the last frame and this one). Do your collision detection against the ball line and each line made from your points (there's tons of line-line collision detection algos on the web). What you'll get out of an algorithm like that is the time the collision takes place in the current time step, as well as the normal of the colliding line, which will give you the reflection angle.
If you don't know Vector math, then learn it, it'll make your life a ton easier. Again, there are tons of implementations of a Vector2 class on the net.
You can arbitrarily remove parts of the wall as needed by just ignoring those points in your check.
Another lazy solution would be to use a physics engine like Box2D http://box2dflash.sourceforge.net/ or Nape: http://code.google.com/p/nape/ - it might be overkill for what you want for your game, but hey, it's easy.
For bonus points, another technique which might be easier for you is the Separating Axis Theorem, which is used in the flash game N: http://www.metanetsoftware.com/technique.html

Any known solutions for Image Differencing in Actionscript?

I'm working with a few programming buddies to create an AS interface to the kinect and one problem we're running into is image differencing. We need to be able to throw out image data that doesn't change from image to image so we can pin-point only things that are moving(i.e. people).
Anyone have any experience with this or a direction we can go?
I would consider creating a pixel bender shader to find the difference and also do any other math or tracking. Pixel bender gets its own thread outside of the normal flash player so you can get some more horse power for your setup. Pixel Bender shaders can be applied to bitmaps, vectors, or video so I think it is perfect for this project. Good Luck!
http://www.adobe.com/devnet/flash/articles/pixel_bender_basics.html
And is is a full collection of shaders including difference
Take a look at the threshold method on BitmapData.
It'll allow you to do this stuff. Their docs have a simple example so check that out.
It might be a long shot, and this is just me rambling, but in sound theory (strange how I'm relating it to image cancellation, but here goes...) the concept of cancellation is when you take a wave sample and add its inverse. It's how you make acapellas from instrumentals + originals or instrumentals from acapellas + originals.
Perhaps you can invert the new image and "normalize" the two to get your offsets? I.e. the first image is 'black on white' and the second image is 'white on black', and then detect the differences for the bitmap data. I know I did a similar method of finding collisions with AS3 a few years back. This would, in theory, cancel out any 'repeating' pixels and leave you with just the changes from the last frame.
With BitmapData your values are going to be from 0 to 255, so if you can implement a cancellation (because a lot of parts of the image are going to stay the same from frame t frame) then you can easily find the changes from the previous frame.
Just a thought! Whatever your solution is it's going to have to be quick in order to beat the flash runtimes' slow speeds. Your Kinect read FPS rate will be greatly hindered with bad code.
Here is some frame differencing code I wrote awhile back. It uses bitmapData: http://actionsnippet.com/?p=2820
I also used this to capture moving colors in a video feed: http://actionsnippet.com/?p=2736