forums

TNT Basic Forums > Programming Q&A
Sprite Collision Detection
< Last Thread     Next Thread >
Author
Thread        Post A Reply

06-25-2003 03:27

Posted by:
Kevin Harms

Click Here to Email Kevin Harms   Find more posts by Kevin Harms


what is a good method to moving back a sprite after detecting a collision with another sprite?

kevin

06-25-2003 14:23

Posted by:
MapMaker

Location:
Edmonton, Alberta (Canada)

Click Here to Email MapMaker   Find more posts by MapMaker

Well, do you mean making it move the opposite direction, or moving it back to where it started?

06-25-2003 15:55

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

he sure means go back one step so they don't collide any more.

Easy, just make them assume the coordinates they had before. How? by making them go back the same amount the went forward in the last frame

06-25-2003 23:02

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

try this code:

int x,y,oldx,oldy

while 5=5

' where you make your sprite move
sprite 1,x,y,1
x=x+1
y=y+1

'where you define another sprite
...

' where you detect collision
if sprite col(1,2)=2
x=oldX
y=oldy
end if

'the end of the loop
oldx=x
oldy=y

draw frame
wend

06-26-2003 00:10

Posted by:
Kevin Harms

Click Here to Email Kevin Harms   Find more posts by Kevin Harms

if i make the go back to the original position, that won't work to well if i'm moving the sprite like 10 pixels per frame or so...

i guess i could try slowly stepping each sprite and testing for collision, but i don't know how the performance will be if i have 20 or so sprites?

thoughts?

06-26-2003 00:59

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

>if i make the go back to the original position, that won't work to well if i'm moving the sprite like 10 pixels per frame or so...

??
Can't do much about it if you dont wanna break your head... you might check collisions with circles centerd in the objects, that way you can make the colliding sprites distance equal to radius of the first+radius of second, but I guess it's not the way to go.

I think there's no other solution.

06-26-2003 01:01

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

ooops...

Oh, you say going back a little step at a time until sprites stop colliding? Smart!

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.