forums

TNT Basic Forums > Programming Q&A
Exact collisions
< Last Thread     Next Thread >
Author
Thread        Post A Reply

01-01-2006 20:17

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

I've been trying to make an example that has exact collisions with two sprites (sprite two is the landscape).

All objects that collide with the landscape have four variables: (x, y, xv, yv)
Their positions and velocities.

Can you help?

01-01-2006 23:14

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

exact as in pixel perfect.

i don't think you could do that in tnt basic. you'd have to test to see if the two bounding boxes that contain the sprites overlap and then read back from the frame buffer to test if the overlap only contains trasparent color, whatever that may be.

maybe i've misunderstood what you mean. could you elaborate?

01-02-2006 20:14

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Exact collisions

You mean like a sort of 'Lemmings' thing where they walk on the very top of the landscape?

You'd have to mask both images and use the appropriate sprite settings in order to get the hit. Once you've got it you need to find out what has hit what, and the only way to do that would be on a pixel by pixel basis. Using the 'Lemmings' analogy you'd work from the bottom of the sprite upwards, checking each mask (not image) to see if the overlapping pixel colours were equal. If they are you have a hit, otherwise you don't. To speed the check, only look for a collision where the sprite mask indicates a colour, and keep the sprite sizes to a minimum or it'll run like a dog. Happy coding.

Danny (nods)

01-02-2006 20:30

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

isn't there a point in polygon function in tnt basic?

you could always use a polygon as your collision geometry. like, say you have a hill in you background sprite, you could let the polygon follow the outline of the hill and check for collision between the sprite and the polygon. this way you could also rotate the sprite so it lined up with the edge it collided with if you wanted to. you could also make the player run faster down hill and slower up hill, stuff like that. and it would be much faster then pixel based collision.

01-02-2006 23:23

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Well, I made something that almost worked. I just used TNT's exact sprite collision feature. The only thing that was wrong with it was that sometimes the player came out the other side of the sprite, and the friction was high while colliding.

01-02-2006 23:23

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Well, I made something that almost worked. I just used TNT's exact sprite collision feature. The only thing that was wrong with it was that sometimes the player came out the other side of the sprite, and the friction was high while colliding.

01-03-2006 06:14

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

sounds like a penetration issue. the collision is being detected when the sprite is like half way in the landscape. try reversing it's direction when you detect a collision. if it's penetrating then it will vibrate wildly. before you handel the collision you need to move the sprite so that it is no longer collideing.

01-22-2006 20:08

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

I need help!

I'm working on a sprite engine. I need help on the sprite collisions. Check it out and tell me what you think. If you fix the collisions e-mail me the file at j-a-f@earthlink.net

Sprite Engine.sitx

01-23-2006 08:06

Posted by:
allnodcoms

Location:
hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

I can't see a problem with the collisions...

What are we looking for? Everything looks pretty tight to me. Occasionally you get a 'jump through', where a sprite misses a collision with the background, but your background is only one pixel deep so this is going to happen when you're varying the speed based on unknown (or unrestricted) forces.

If you drop the red ball off the screen and leave it for a bit, then try and put it back it skips several checks, or all of them, as you don't kill the acceleration when it leaves the screen (it carries on getting faster and faster). This suggests that it's more to do with the speed of the objects, they are basically just 'jumping through' your scenery.

If you want to stay with single pixel precision backdrops, the only thing I could suggest is a thing called 'look ahead' polling. Basically you know the speed of the object and its direction of travel, so loop through this path, one pix at a time, and see if that pix is 'blocked'. If it's not then move the object, but if it is then just place it at the point of collision, flag it as a hit and deal with as normal. You could kick this code into place when the speed exceeds a predetermined limit.

Basically I think your collision code is working fine, I'd just take a closer look at your physics model.

Danny (nods)

01-23-2006 13:24

Posted by:
Jacob

Location:
San Francisco, CA

Click Here to Email Jacob   Find more posts by Jacob

Use the mouse button to add objects.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.