How to create car collision in AS3? - actionscript-3

I have a background with a top view motorway and forest on the sides and I want it so that when the car touches the green forest area the game changes to another scene. I have tried to put a line on the forest area and make it so that if the car hits the line switch to another scene but I have failed. I'm using action scrip 3. Thanks.

One solution might be to put the track pavement graphic in a separate sprite that sits on top of the green forest. Then you can hit test to see when your car is not touching the road. That would mean it's in the forest.
There's a simple top-down racing game in this book that uses a similar technique: AS3 Game Programming University (site)
Taking a look at that book might be really helpful if you are just starting out with games.

Related

infinite world creation with libgdx

I am a newbie and a little lost. Which classes or tools do you recommend to create an infinite libgdx game world with collision detected available, so that the player can walk on it? The concept is shown in the images below. The camera (phone screen) moves around the world in a non-linear fashion(on a boundary between green and white in this image), tracking the character. All I need is some place to start, I will be good from there on.
EDIT: Basically the problem is to create an infinite world, perhaps self generating is a better world, with collision detection enabled. I have tried nothing because I don't even know where to start. I only need to be directed in the right direction on this.
Just to give you a few keywords to search for:
Infinite world: Procedural generation
libGDX collision detection:
Box2D or bullet (physics engines inside libGDX)
libGDX provides also Circle or Rectangle to check for overlapping
Camera tracking: ViewPort, Culling

How do i make an object collide with a color?

I'm making my very first game with libgdx, and it involves making levels with many right angles, very much like a maze. All I know how to make a collision is to make an invisible rectangle on each wall that collides with the player, but with so many walls this is an irrational solution, to make a rectangle for every single wall.
Since all the walls and edges will be black, is there a way I can make it so the player collides with anything the color black? That would be an incredible help.
I would suggest taking the time to learn how to use tile maps. Using tiles should help you accomplish what you want and there's already a bunch of tutorials on this, a few of them listed below.
Tile maps on the libGDX wiki
A tutorial on tile maps from gamesfromscratch.com
A YouTube tutorial on tile maps, which also covers collision detection
The tutorials I link may not apply exactly to your case, but they should hopefully point you in the right direction.

Box2D AS3 - Refreshing the Shape or Hitbox?

I'm currently trying to implement a "crouch" function in my game. I'm using WCK with Box2D.
I have something rather basic, I generate my main character as an extension of a shape. This means that collision is automatically generated from the getgo. This is wonderful for a lot of things, but not everything.
I have a crouch/roll function. The problem is that the hitbox for crouching and standing are the same, so if a box drops onto you while crouching it "levitates" ontop of you since the hitbox is still the standing hitbox.
How would I go about "refreshing" the shape collision? Is there a way to delete the collision and make Box2D recalculate?
It's possible to filter contacts and prevent them from happening (using a contact listener or iterating the world's contact list) but I think there are better ways to do what you want.
You could split the body in two parts, and connect them with a prismatic joint (limits and motor enabled, collideConnected disabled). Standing up you'd have the motor push the parts apart to the upper limit and when crouching you'd pull them together to the lower limit thus reducing the height.
If you need really different shapes (e.g. a rectangle when standing and a circle for rolling around metroid style) this might work: Add both shape's fixtures to the body and use mask filtering to prevent the one you don't need from colliding with anything.

Box2D and Sand in AS3

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.

AS3 car race game?

I am trying to make a racing game with an overhead view looking down. There will be a separate mc for the ground and another separate mc for the players car. How can I do this? O ya and just in case i am thinking the way I did:
I tried to "rotate" the ground but when the car moves down the ground it moves away from the registration point, so therefore it rotates non relative to the car i want to make this game in as3.
Put the car on top of a separate holder movieclip, and put the graphics for the ground inside the ground holder. As the car moves and rotates, apply rotations to the holder MC, but apply movement to the ground inside the holder. This way, rotations will always take place relative to the registration point of the holder, but the ground graphics can still move relative to that point.
Not quite sure what you are looking for. In the meantime, you can look at the online Risk Game I helped built. Once in the site, click Super Commuter. If this game is similar to what you are trying to build, you can ask questions relating to what you observe there.