Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Need Help : Collision precise point

Author
Message
xGEKKOx
AGK Master
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location: Italy
Posted: 20th May 2013 21:05
I want to calculate the exact points that collide between two sprites.
I explain: i'm doing the new version of my karate, and we are doing great things, now this time i want to show the crash point as in the major beat em up.

For example if i hit with a punch in the face, i wanna do the crash animation (is like a POF! of air) in the center of the collision.

Can i do it with the new commands?
Are those commands only available in the 108?
Is there a way to do this without the px by px manipulation?

Thx in advance!

Long life to Steve!
Naphier
14
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 20th May 2013 21:22
I had to do a bit of calculations for this in dFenz.
In the last level the mothership has arms which are part of a bigger sprite. I had to hard code the locations of the sprite rlative to the sprite center. This allowed me to place an explosion at the same location as one of the arms.

You'll probably have to do something similar. I'd suggest mapping the position of the fist or foot in relation to the center of the attacker's sprite then using that location to create your POF sprite.

It takes a little bit of time, but it's not too bad.
What I did instead of calculating was I used photoshop's INFO panel to show me the distance from center of the frame to the arm.
Then you save all of them in a table of sorts and look them up as needed. Much faster than any commands that AppGameKit will give, but it does take a bit of work on the front end.

If you want to go this way and still need help I'd be willing to share some snippets with you that show how to do it. Just shoot me an email.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 20th May 2013 21:25
GetPhysicsCollisionX/Y are available in v1076.

You use the GetPhysicsCollision(sprite1,sprite2) to test for collision (overlap) of two sprites and then use the GetPhysicsCollisionX/Y commands to get the point they collide at.

At least that is what the help on the commands suggests might work.

You need to make sure that there is physics set on the sprites and that the physics shape is correct for each one.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 20th May 2013 22:08
with Physics:

Contacts:
GetContactSpriteID1
GetContactSpriteID2
GetContactWorldX
GetContactWorldY
GetFirstContact
GetNextContact
---------------------------
GetSpriteContactSpriteID2
GetSpriteContactWorldX
GetSpriteContactWorldY
GetSpriteFirstContact
GetSpriteNextContact
---------------------------
without physics:
Collision:
GetSpriteCollision
GetSpriteDistance
GetSpriteDistancePoint1X
GetSpriteDistancePoint1Y
GetSpriteDistancePoint2X
GetSpriteDistancePoint2Y
GetSpriteInBox
GetSpriteInCircle
xGEKKOx
AGK Master
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location: Italy
Posted: 21st May 2013 14:08
Well, as i don't use Physic, i think i must use the GetSpriteDistance points, right?
After i get the distance, i can use the Pitagora's theorem to get the middle of the "ipotenusa"???
Can be this a way to calculate it?

Or there is a faster way?

@Naphier
I used your way in the past, and it was not bad. But the sprites animations are 75 * 14 characters, and i don't want to do this.

I hope using the SetSpriteShape to 3 and the Distance will be fast enough.

Anyone of you have an example on how to use the MemoryBlock to read the png in C++?

Long life to Steve!
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 21st May 2013 14:55
I think you'd be better off using an encoded memblock image. Like, if your fighter sprite is on a single sprite sheet, you could use a lower resolution version, coloured to highlight the different parts of the body. For example, the head might be red, weak parts of the body green, strong parts or defending parts blue. Then, once you have that collision point(s), you can check the enemy sprite frame on the memblock, check the colour of the pixel, and know exactly where the hit landed.

You don't have to use a memblock, you could use an array with a fixed resolution of say, 32x32 (should be accurate enough).

Doing it this way means you have total control - when the fighter is moving, jumping for example, you might want to make the collision data mostly green, to signify that the fighter is vulnerable, then when the fighter is defending, then the arms for example could be blue, so you can tell when the hit was on a defended part of the body. You could even use this for full collision, rather than using box2D polyline based collision, you could cross-reference the sprites to detect hits - with the number of checks needed for a 2D beat-em-up, and a 32x32 area on each sprite, it shouldn't be a big deal for performance.

One issue that I would worry about, is how effective box2D is at changing the sprite collision shape - the default just wouldn't have enough polylines to do a decent job, so you'd have to add your own polyline 'shield' for each frame. Personally, I'd go for the colour coded 32x32 sprites, I think it'd be easier in the long run and more accurate. You could even have key points on the collision that generate blood particles when hit - like the mouth and nose. With the level of control that this method would afford you, there's a lot of cool stuff you could do - have attacks that use any part of the body, knees, headbutts, both feet at once, because it can be controlled with the collision data to an exact degree.

I got a fever, and the only prescription, is more memes.
xGEKKOx
AGK Master
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location: Italy
Posted: 21st May 2013 15:14
The MemBlock is only in the 108 right?

Long life to Steve!
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 21st May 2013 15:29
Yeah, probably, but you don't have to use a memblock, you can do the same job with an array as well - like have a 3D array, XY for the 32 pixels, and Z for the number of sprites. Then you'd make a little program in DBPro or something to take the pixel data from an image, and save it in a format that can be loaded into AGK.

I got a fever, and the only prescription, is more memes.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 21st May 2013 15:44 Edited at: 21st May 2013 15:45
the middle between two points is
x= (x1+x2)/2.0
y= (y1+y2)/2.0

if you have a normalized direction you can multiply with a length if you use a sprite with circle shape.
dx=x1-x2
dy=y1-y2
l=sqtr(dx*dx+dy*dy)
dx=dx/l
dy=dy/l
x=x1+dx*radius
y=y1+dy*radius

i think you will show a crash sprite and it not needed to be pixel perfect collision because its bigger and overlap the other sprites.

maybe you can use physics and the collision system with sensor option.
Impetus73
13
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 21st May 2013 15:53
Why not chop the sprite up into smaller sprites, then just check what subsprite you hit?

Headsprite, armsprite, legsprite and so on.

A bit harder to animate though... maybe use overlay sprites that are invisible, if it's possible to check for collisions with invisible sprites.

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
xGEKKOx
AGK Master
15
Years of Service
User Offline
Joined: 7th Dec 2008
Location: Italy
Posted: 21st May 2013 17:38
Well the smaller sprites seems the old way of tiling like in double dragon and street fighter, but it takes very long time to create the animations.

I thought to do like Marcus said.
So i can avoid the MemBlock as if i'm not wrong it is present only in the 108 version.

i will divide the sprite in 3 parts.
The sprite is 256 so i will divide :
Sector1 = 0 -> 85; Head
Sector2 = 86 -> 171; Center
Sector3 = 172 -> 256; Legs

I will take the distance X and Y from the two sprites and i will compare if is in one of this sectors.
And i will generate the crash animation in the center of this sector.

Maybe will work.....

Long life to Steve!

Login to post a reply

Server time is: 2024-11-24 14:33:22
Your offset time is: 2024-11-24 14:33:22