Game Collision detection libGDX - java

I can do 2d collision detection of boxes and circles ,but I have a question . How can I do collision detection in this situation (1,2).I am using libGDX game engine for creating games.

Fixture (1) in your world should most likely be a ChainShape. ChainShapes are determined by an array of Vector2 objects, the more you have, the smoother the ChainShape tends to be.
Without very tedious scripting, making a fixture from an image is done by putting vectors at relatively close points to make a shape that looks similar to the image.
Further information on how to create a ChainShape can be found here.

Related

Game Development, Collision

I'm new to the game development and I'm trying to code 2D RPG game. im using png images to create objcts and move around. So it is pretty easy to detect collision between rectngles and other simple shapes like this.
if(object1.collides(object2)){
}
what is best way to detect collision of image objects like player, or npc?
The most common way is to create a hitbox that is the approximate shape of your object. The hitbox can be very simple like a rectangle or circle around your object, which is actually invisible.
Have a look at this example, the black box is the hitbox of Mario and you only need to check its boundaries:
But if you really need precision, then you will need to go through the pixels of an image and create the custom polygon. However, the more complex your polygon is, the harder it is to detect collision. Most of the time, game developers rely on physics engines to deal with it.

Libgdx Platformer 2d beginning adding enemies

I have read The guide to implementing 2D platformers
http://higherorderfun.com/blog/2012/05/20/the-guide-to-implementing-2d-platformers/
I want to develop the second way (Type #2: Tile Based (Smooth))
Collision is still determined by a tilemap, but characters can move freely around the world.
I have made a class Enemy with position and velocity.
How could I move the Enemy in the world when it is not visible in the screen yet? There is any GitHub example of this issue?
I am not using Box2D. I have started with the Super Koalio Example:
https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/superkoalio/SuperKoalio.java
My problem about rendering was solved using OrthogonalTiledMapRenderer

Physics-based/Polynomial Animation with Box2d (Java)

I'm creating a 2d game using the Java version of Box2d.
I know that the engine is generally paired with a separate library to handle animation, but I'm looking for something simple, with a more rustic feel, so I'm considering handling the animation from scratch.
The animation I am trying to create is something for the collision of two objects.
I'm using openGl to handle the graphics, and I pretty much have everything set up with the fps and rendering, it's just a matter of tweaking the frames to make it look smooth.
I tried bliting images of some things that I drew myself and it looked atrocious. I think the main problem is that the animation frame images are not linked to the physics forces and so they don't blend well.
What I want to try next is a sort 'spark effect' using a small number of pixels that sort of resemble 'dust' exploding off of the colliding images. If you've ever played dxball, you may recall a similar effect when the ball collided with the paddle at high speed.
As you can see in the above image, the principles are fairly simple. I figure by creating a set of small bodies with fixtures, I can use the box2d engine to produce this effect. I already have code that grabs the point of collision for all bodies, and am familiar enough with parabolic functions that I pretty sure I can create the force direction.
I'm just not sure if there is a better way of doing this, or how to apply a polynomial function to a body like in the image.
Does anybody know how to achieve this functionality with box2d? Any built in methods or documentation that would be helpful?
As a point of reference, the following snippet of code demonstrates the drawing of a small, red box on all of the collision points.
for(Vec2 point : listener.worldmanifold.points){
glPushMatrix();
newpos = point.mul(30);
glTranslatef(newpos.x, newpos.y, 0);
glColor3f(1,0,0);
glRectf(-2, -2, 2, 2);
glPopMatrix();
}

how to detect collision between two sprites in libgdx?

i am learning libgdx. i want to create a 2d fps game using libgdx, which is basically no physics environment. in that case lot of collision will be there (for example lot of bullets hitting multiple objects). i need to check intersecting of every sprite's rectangle with other sprites. in this way there may be thousand sprite's, checking every sprite with other 999 sprites in every time isn't definitely not a good idea.
libgdx has scene2d which has hit detection api's, is that solve my problem?
or
i should use box2d collision detection?
or
is there any other way to detect collision in libgdx?
i want to create a 2d fps game
As much as i know FPS means "First-Person-Shooter" -> a shooter with the first person perspective. That means, that it is 3D.
So pleas clarify what you mean.
Now to the collision detection question:
Scene2Ds hit detection is used for input like touch or
mouseevents. So it is used to detect, if an Actor is touched,
clicked...
Box2D is a 2D physic-engine which can not only do collision
detection for you, but it can also do the collision response as well
as the physics simulation (gravity and things like that).
Libgdx offers the Intersector class, which you could use for
overlap tests. The organization/the management of the collision
detection is up to you.
It would be better if you tell us how your game should work, how your world should be managed etc.
For example, if your world is tilebased, the collision detection between wall and player could be a simple check, if the tile is occupied -> collision, if not -> no collision.
Also it is important to know the shapes of your objects. A rectangle-rectangle collision detection is different from a rectangle-circle collision detection.
So now there are 3 solutions for your problem:
- Use Box2D and read tutorials on how to use it
- Do some research on collision detection, read tutorials and take a look at some sample projects
- Give us more informations about the game, its objects, their shapes etc.

libgdx ragdoll physics with animation

I'm in the planning stages of game dev. and am wondering whether or not to pick unity or Libgdx. I already know quite a bit of java, and I want to make a 2D sidescroller that uses ragdoll physics with animation. I have been looking pretty hard, but haven't found a good resource for this yet with Libgdx. It seems possible with Unity though. The resources I have found so far with Libgdx are :
Rube
Glee2d
Spine
Blender
So far with this it seems possible to make a level with a skeletal 2d animating sprite, but is it possible to apply ragdoll physics to this creation so, for example, if an enemy was shot it would react like a ragdoll?
I appreciate any help!
Thanks,
You could clearly use libgdx for that.
You'd have to create the ragdoll as box2d bodies (which can be done with rube). For rendering the ragdoll, you could use the setUserData() methods in box2d to bind an actor to the body/fixture. After each simulation step you would update the actors and create the proper rendering.
You could then place the ragdoll somewhere and shoot it with some other box2d body, let's say a cannonball...

Categories

Resources