forums

TNT Basic Forums > Programming Q&A
sprite collision detection
< Last Thread     Next Thread >
Author
Thread        Post A Reply

06-09-2003 03:43

Posted by:
shivers

Click Here to Email shivers   Find more posts by shivers

does anyone know why this sprite collision isn't working? collision is an int. the if then's at the beginning are just to print what the player collided with for debugging purposes, the console is coming up clean though. Also, when i just say "if collision > 0 then print "collision" it does print "collision" so the problem is in the sprite image detection thing.

collision = sprite col (1,0 to 10000)

if collision > 0 and sprite image (collision)=006 then print "streetsign"
if collision > 0 and sprite image (collision)=008 then print "crate"
if collision > 0 and sprite image (collision)=007 then print "trunk"
if collision > 0 and sprite image (collision)=009 then print "hydrant"

if collision > 0 and sprite image (collision)=006
if speed > 0 then speed = -2
if speed < 0 then speed = 2
end if

if collision > 0 and sprite image (collision)=008
if speed > 0 then speed = speed/1.5
if speed < 0 then speed = speed/1.5
sprite off (collision)
end if

if collision > 0 and sprite image (collision) = 007
if speed > 0 then speed = speed/2
if speed < 0 then speed = speed/2
end if

if collision > 0 and sprite image (collision) = 009
if speed > 5
speed = speed - 9
else
speed = speed/2
end if
if speed < 5
speed = speed + 9
else
speed = speed/2
end if
end if

06-09-2003 23:14

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Maybe it's because you're using 009 instead of 9 and such

06-10-2003 00:08

Posted by:
shivers

Click Here to Email shivers   Find more posts by shivers

arrrg, no, thats not it...i'll get this eventually...maybe

06-10-2003 00:20

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

I've never seen Sprite Col causing problems. Maybe check you're really using sprite 1, and that it really collides with another sprite. Maybe write print Collision to see what the id of the collision is.

06-10-2003 00:51

Posted by:
shivers

Click Here to Email shivers   Find more posts by shivers

good idea, i'll try that

06-10-2003 00:57

Posted by:
shivers

Click Here to Email shivers   Find more posts by shivers

i told it to print collision and print sprite image(collision) and it would print 116 for collision and -1 for sprite image...why is that?

06-10-2003 01:03

Posted by:
shivers

Click Here to Email shivers   Find more posts by shivers

could it have something to do with the image bank? I would be surprised because the sprites are loading fine

06-10-2003 03:55

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

i have a related question. when i use sprite col and one of the sprites is accelerating, like as if were falling, the accelerating sprite embeds itself into the sprite it collides with, and if it is going fast enough, it will go right through it. any thoughts?

06-10-2003 21:40

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

Well I'm not sure about shiver's question, it sounds like the sprite has lost track of its image bank somehow? Are you unloading images or change the sprites bank or anything?

Not very helpful I know, but I may be able to give some pointers on puffin's question:

Generally, after detecting a collision you want to move the colliding sprites back to where they were before the collision, ie before you moved them and caused a collision. If you just leave them where they are then when they're drawn they will be colliding. The absolutely correct way to do this would be to move and test for collisions with your sprites one at a time. Eg move your sprite, do a sprite col for it, if it's hit something then undo the move and go onto the next sprite. This is going to be computationally slow though as you'll end up doing twice as many sprite collision tests as you would if you just moved them all and tested them all. But the general idea is to make sure sprites can't embed themselves by testing them immediately after you've moved them and moving them back if they've collided.

As for the sprites moving through each other because they're going too fast you could try if the sprite is moving fast enough to potentially pass through other sprites without intersecting with them then do two moves, ie move it half way, do a sprite col, then move it the rest of the way.

Hope this helps!

Mark

06-10-2003 21:51

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

I often had problems with sprite image(), especially in harware mode. ( My computer is so old, I've experience all possible and impossible bugs with harware mode ! )

06-11-2003 04:27

Posted by:
shivers

Click Here to Email shivers   Find more posts by shivers

yeah, this is in hardware mode. but my computer should be able to handle it. i have 800mhz, 512 megs of ram, 32 megs of vram

06-11-2003 16:41

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

Hardware mode IS buggy anyway.

06-11-2003 22:03

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

yeah, I know, it's full of bugs and crashes often...
WAHAHAHAHAHAHA!!! Mark will hate me for this ;-)

No, actually hardware mode is fine for me, except for the collision detection is quite off.
In my game RadicalRebound I now calculate all collision detections manually: collisions with circles are easy, but I had to remake also the critical collision with the shield, that is a rotated rectangle, and I tell you it was not easy to code. Well, by hand on paper it' s not too difficult, you only need to calculate the equations of the 4 lines that delimit the rectangle and check if another sprite is in it, but with the crazy coordinate system that reverses the y axis and the degrees of rotation calcualated clockwise there are always problems.
Well, actually now it works and it's better than automatic collision det ;-)

What' s the max FPS you get in hardware mode with no spites? I' d like to know this especially from those with a G4. I get 35-37 on my 350 G3

06-11-2003 22:32

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

somtimes in hardware mode i start my game and the map dosn't load. cazy shit man.

06-12-2003 15:28

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

The problems I've experienced in Harware Mode:

1- Map will not load
2- Sounds will not load
3- Sprites will appear as a green square
4- SetSpriteColor is going crazy
5- Maps are not drawn correctly on screen when I use a viewport
6- Sometimes it crashes
7- Maybe I forget some other?

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.