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.

2D All the way! / cant reach the corner

Author
Message
dax24
21
Years of Service
User Offline
Joined: 2nd Feb 2004
Location:
Posted: 13th Apr 2004 18:09
i have made a collision test program so i can work out the collision system perfectly. the only problem i am getting is if i go to the bottom right of the box it will pixel perfect collision. if i move him to the left or up he will not even reach the top yet the program will say there is a collision. can someone please look at my code and help me out as i am stuck?
Scouseknight
21
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 13th Apr 2004 18:56 Edited at: 13th Apr 2004 18:59
Try wrapping your code like this :



This will only check for the collision when the player reaches the centre of the cell.

I am not at home to try the code myself but I remember having to do something similar in a maze game I wrote.

Basically, if the floating point version and integer version of the calculation are the same, then you are in an the centre of the cell rather than just bleeding into one.

dax24
21
Years of Service
User Offline
Joined: 2nd Feb 2004
Location:
Posted: 13th Apr 2004 19:17
i have tried what you said but it seemed to make it worse by not letting me move left or up at all. if you could have a look later and let me know what you think it would be a great help.
Scouseknight
21
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 13th Apr 2004 19:27
Aye will have a look - I finish work in a few minutes so I'll be able to get stuck in then.

dax24
21
Years of Service
User Offline
Joined: 2nd Feb 2004
Location:
Posted: 13th Apr 2004 19:39
thanks mate.
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 13th Apr 2004 19:46
Well, take all of the # out of the program, they aren't needed, and you aren't using them properly anyway. They could cause you a bug.

Scouseknight
21
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 13th Apr 2004 20:07
I think I have it working now :



It works in a similar way to the centre of square method but it breaks it down into horizontal and vertical centering instead.

Scouseknight
21
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 13th Apr 2004 20:11
Pincho - the floating point variables were being used because the array-based collision method needs to divide the physical position of the sprite or graphic by the width of each cell - you end up with fractional values unless the image is blob-on centre of a cell - so comparing the value to the integer version of itself determines dead centre.

I concede there may be better ways of doing this but it was my original example that was being used so I take responsibility for that

dax24
21
Years of Service
User Offline
Joined: 2nd Feb 2004
Location:
Posted: 13th Apr 2004 20:18
sorry mate, i have just put that code in and it doesnt seem to work???

the sprite walks straight through the tiles and also finds collision where there is no collision.
dax24
21
Years of Service
User Offline
Joined: 2nd Feb 2004
Location:
Posted: 13th Apr 2004 20:20
my mistake scouseknight.

if i remove this line of code: if playerx# = playerx or playery# = playery

it works fine.

thanks alot for your help
Scouseknight
21
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 13th Apr 2004 20:24
Gah sorry I forgot to take that out!

Glad it works now - don't you just love collision detection

dax24
21
Years of Service
User Offline
Joined: 2nd Feb 2004
Location:
Posted: 13th Apr 2004 20:26
i have to admit its a bit of a mind bogle trying to sort it out.
dax24
21
Years of Service
User Offline
Joined: 2nd Feb 2004
Location:
Posted: 13th Apr 2004 20:28
just found another problem with it now, will explain in a moment
dax24
21
Years of Service
User Offline
Joined: 2nd Feb 2004
Location:
Posted: 13th Apr 2004 21:09
the problem wiht it now is that when you put in a couple of more blocks in the in the square (putting some more 2's in the array) the program doesnt detect them properly???
Scouseknight
21
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 13th Apr 2004 21:12
I'll do the same with the version I still have here - watch this space!

Scouseknight
21
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 13th Apr 2004 23:46
Crikey what a nightmare this was!!!

Try this for size :



Login to post a reply

Server time is: 2025-05-14 20:40:12
Your offset time is: 2025-05-14 20:40:12