I'm in the process of developing a 2D fighting game in the same style as Capcom's Street Fighter Alpha for the iPhone. For collision detection, I'm thinking about creating several hit boxes per sprite frame in an animation and checking for collisions between them in the main game loop. Are there any tools for creating hit boxes on sprites and generating this metadata (say in a .plist or .xml)?
How have other 2D fighting games developed by the cocos2d iPhone community handled collision detection and the generation of useful metadata?
Thanks for the forthcoming responses.
In a fighting game, collision detection is actually not performed (or should not be performed, that is).
What you would want to do is determine the distance of Player A from Player B when Player A performs an "attack". Player A's attacks are "static":
High Punch = 64px reach
Low Punch = 54px reach
Mid Punch = 45px reach
High Kick = 64px reach
etc, etc, etc
You would then determine, based on the attack performed and the distance to Player B, and the current state of Player B - whether the attack "landed", was "blocked" or "missed" (High Kick Attack against Crouched Enemy is "miss", while Low Kick Attach with Crouched Enemy NOT in Block is a "hit").
It's a series of "rules" - if the two players are within a specific distance of each other, and the states of each player are correct for the attack, then the attacker "lands", or the defender "blocks" or the attacker "misses".
Related
I am trying to use bullet physics library in my opengl game engine for collision detection.
I am not trying to do anything complicated, I only want to know when things collide in the 3d world. I am only using box shapes and I have no interest in moving the objects using physics (I have even disabled collision response for my rigid bodies).
I have managed to get the collision to work doing the following:
First, each frame I update the rigid bodies world transform based on the entity's transform it is attached to. For example I move my player right, the rigid body (and the bounding box) moves with me.
I am checking if 2 objects are colliding using this code:
void PhysicsManager::myTickCallback(btDynamicsWorld *world, btScalar timeStep)
{
int numManifolds = world->getDispatcher()->getNumManifolds();
if (numManifolds > 0)
cout << "COLLISION" << endl;
}
myTickCallback is the dynamics world internal tick call back: dynamicsWorld->setInternalTickCallback(myTickCallback);
What is weird now is that when I start up the game, I move my player on the other object I want it to collide with and it starts spamming COLLISION. If I leave the player on the object it will keep spamming it. However, if go away from the object and go back into it several times, after a while it just stops writing COLLISION.
I have checked if the rigid bodies are moving (if there is collision response) and there isn't.
This could be a problem in the game I am trying to create because I want the player to be hit by projectiles and it wouldn't be right if he stops getting hit after a while.
I have an issue where when I use the physics system to have collision between the character and the wall, the Sprite will SOMETIMES vibrate when you hold to move into the wall. As an additional thing as they may be related, if I turn up the player's speed value they're able to glitch through the walls. Right now the collision system I have is really basic, so there isn't much coding but here's related info.
Wall's density is set to 0 while player is .1
Room has physics enabled but has no set gravity
I have a drag and drop collision event with only a comment in it.
https://docs.yoyogames.com/source/dadiospice/001_advanced%20use/more%20about%20objects/physics.html
Restitution: In physics, restitution is defined as "the return of an object or system to its original state after elastic deformation", but as the fixtures in the GameMaker: Studio are really rigid bodies and cannot be deformed, restitution is really a way of saying how "bouncy" the fixture is. This setting will affect how much an object "bounces" when it collides with other objects and is co-dependant on other forces that act on the instance like gravity and friction.
That could be ansver to "vibrations". Else you may tru to create code which will check if object is trying to move towards obstacle and stop its movement to prevent built-in physics from causing any problems.
wall skipping: This is usual behavior of built-in game-maker collisions. main problem is that game-maker "teleports" objects "by speed in its direction", which means that when speed is greater than size of any object, game-maker collision system may fail.
I have seen this before, and making my research i've discovered that if you create allot of circles objects in box2d, then apply a color, then blur it and at the end sharp it a little bit ( same stile like "Where is my water" game created by disney ).
But of course in a game like limbo, with a huge world this is extremely expensive.
Since i have seen this in a few games over the internet i still trying to understand how can i build this with box2d ? ( the games over the internet where/are created with in flash, and i want to do it in cocos2d for the iOS platform )
a few examples about how the water works, for those that didn't played the Limbo game:
1.A box will flow on the water, the box will enter in the water only half of it and half of the box will will remain above the water. If an object (like: the player ) will falls above it the box will have the end of the titanic, it will sink.
2.A rock will sink.
3.The player, well i guess here will be different choices.
4.A boat, for the bout i know a bool should do the trick BOOL canSink; but again how should i make that water effect ? balancing the object on it, an bouncing if the object falls in the water, and for sinking a slower velocity ?
It may look like allot of questions,but at the end is only the " How to create the water effect in box2d?"
I guess you're looking for buoyancy effects, here you have a couple of interesting resources.-
http://www.iforce2d.net/b2dtut/buoyancy
http://personal.boristhebrave.com/project/b2buoyancycontroller/demo
As for the water waves effect, you can take a look at.-
http://www.sideroller.com/wck/?f=6
http://www.cocos2d-iphone.org/forum/topic/25494
Hope it helps.
I'm having hard time learning collision detection by experience. I'm making a box game, à la Minecraft, and am at the stage of implementing collision detection.
I've done x and y axis', since everything consists of cubes I would like to make my own collision detector and make it as light as possible.
Is there a way to make "pixel perfect" collisions, that is when the player's bounding box (or circle) touches a box it registers as a collision? Right now this is what I did:
if(-TOUCH_DISTANCE-1 < yPlayer-yBox && yPlayer-yBox < TOUCH_DISTANCE-1)
{
collisionNorth = true;
}
if(-TOUCH_DISTANCE+1 < yPlayer-yBox && yPlayer-yBox < TOUCH_DISTANCE+1)
{
collisionSouth = true;
}
It basically detects the collision within a certain margin and that means errors, which I don't like :(. Notice the +/-1 which offsets the "collision wall" to the respective side of the box.
This works, on lower speeds, but once there's some action (when I crack up the speed variable) the collision can't be detected anymore since I go too fast and pass right through the cube... Is there a way to make it wallhax0r proof?
This is especially annoying on z axis, when the player falls at high speed and even when defining a respectable collision margin it will ultimately look nasty (player half buried).
You've identified one of the problems of using discrete mathematics to model the path of an object. At time t the object is "here" and at time t + delta it's "there" - without actually having passed through the points in between.
You can get more accuracy by decreasing delta, but ultimately you are going to hit the limit of what you can calculate in that time interval.
If you can detect a collision approaching by using a relatively large time delta and loose bounding box you could then crank up the accuracy, but again you are going to hit limits.
Converting to a continuous model might help - but may take more computational power. You could switch to this when your objects are close so you're not doing it all the time.
Sorry I've not got a definite answer, only pointers.
Usually what you need to do is keep track of the previous position of the objects as well as the current position. Then when you update, you can check if the objects intersected during the time period, rather than if they intersect 'at the moment'.
I've started developing a small multiplayer racing game, obviously we're using all the player prediction, dead reckoninng and lag compensation techniques that Half Life, Quake and Unreal use - however we plan on having dozens of AI cars in the game as well.
Initially we decided to simply send a random seed to all clients and they will calculate AI positions, etc - however, we've reached the following problem:
All clients receive a seed to run AI cars
Clients only receive movement updates for players within their line of sight
Player A hits an NPC car
Player B enters player A's frame
Now since player B didn't receive player A's movement, he'll assume the AI car is still moving as it should, and wouldn't calculate in the fact that player A hit one of those cars...
So long story short - how can you synchronize AI units that were affected by players?
Presumably, your server is aware of any collisions. In that case, simply notify all your clients of collision results--essentially re-seeding the AI on the clients, at the point of the collision, with the new directions, velocities, RNG seeds, etc.