Jump to content
KevKelley

Collision Detection Issue - Teleporting Sprites

Recommended Posts

I think I am stumped.

 

I think I got collision detection down between player0 and the virtual sprites but I have come across an issue where whenever player0 touches a virtual sprite player1 would teleport to the player0 location and linger. I have a feeling the solution is super obvious and has to deal with how I have the player0 "capture" the player1 sprite when they collide because when I deleted the line that ties the player1 coordinates to player0 the teleportation problem seems to be solved.

 

Is it due to placement of the code? Should I create a variable that turns the collision on or off for player0/player1 so that it doesn't teleport or linger?

BBPv020219.bas

Share this post


Link to post
Share on other sites

It says this on the bB page: "The virtual sprites are all player1, so you can't use collision() to detect collisions between them."

 

Do you think that might be the problem?

Share this post


Link to post
Share on other sites

I had followed the other thread where creating a box around each Sprite. I thought I had eliminated any collision statements I had originally made. There were a few "if !collision" statements but I think only preceding each box, like the example had. I will double check in the morning and see if I had missed one when I was deleting my old code.

Share this post


Link to post
Share on other sites

I just double checked and didn't see any collision(player,player) statements. This is the relevant code

 rem player collision with cart

 if !collision(player0,player1) then goto _skipcheck0
 if player0x <= player1x +8 && player0x +8 >= player1x && player1y + player1height >= player0y && player1y <= player0y + player0height then goto _bagboycart

_bagboycart

 
 player1x=player0x+3: player1y=player0y+7:goto _skipcartfollow


_skipcheck0 

 rem cart movement following car


 if player1y < player2y then player1y = player1y+carty
 if player1y > player2y  then player1y = player1y-carty
 if player1x < player2x  then player1x = player1x+cartx
 if player1x > player2x then player1x = player1x -cartx

_skipcartfollow



 rem collision bagboy with customer2
 if !collision(player0,player6) then goto _skipcheck1
 
 if player0x <= player6x + 8 && player0x + 8 >= player6x && player6y + player6height >= player0y && player6y <= player0y + player0height then goto _bagboycustomer2

_bagboycustomer2

 AUDC1=6:AUDF1=20
 player6x=rand:player6y=220
 score = score+5
_skipcheck1

 rem collision with customer2 and cart
 if !collision(player1,player6) then goto _skipcheck2
 if player1x <= player6x + 8 && player1x + 8 >= player6x && player6y +player6height >= player1y && player6y <= player1y + player1height then goto _cartcustomer2
 
_cartcustomer2

 player1x=player6x+3: player1y=player6y+7
 AUDC1=rand+1: AUDF1=rand+1
 score=score-1
_skipcheck2

 rem cart collision with customer
 if !collision(player1,player4) then goto _skipcheck


 if player1x <= player4x + 8 && player1x + 8 >= player4x && player4y + player4height >= player1y && player4y <= player1y + player1height then goto _cartcustomerhit
_cartcustomerhit
 player1y =170 : player1x = rand 
 AUDC1= rand : AUDF1 = rand
 score = score + 25 : AUDV1 = 8

_skipcheck


 rem cart collision with car

 if !collision(player1,player2) then goto _skipchecktwo

 if player1x <= player2x + 8 && player1x + 8 >= player2x && player2y + player2height >= player1y && player2y <= player1y + player1height then goto _cartcarhit
_cartcarhit
 player1y=170:player1x=rand
 AUDV1=8: AUDC1 = 1 : AUDF1 = 31 
 score=score-10

_skipchecktwo

 rem player collision with car

 if !collision(player0,player2) then goto _skipcheckthree


 if player0x <= player2x + 8 && player0x + 8 >= player2x && player2y + player2height >= player0y && player2y <= player0y + player0height then goto _bagcarhit

_bagcarhit

 player0y=32 : player0x = 73
 AUDV1=8: AUDC1 = 3 : AUDF1 = 29 
 player1y=170 : player1x=rand
 score=score-50


_skipcheckthree

 rem player collision with customer

 if !collision(player0,player4) then goto _skipcheckfour

 if player0x <= player4x + 8 && player0x + 8 >= player4x && player4y + player4height >= player0y && player4y <= player0y + player0height then goto _bagboycustomer1

_bagboycustomer1
  AUDV1=8: AUDC1 = rand : AUDF1 = rand 
_skipcheckfour

Share this post


Link to post
Share on other sites

I was talking about things like "if !collision(player1,player6)". I don't think we can do that, if I remember correctly. Don't know if that's your problem, though.

Share this post


Link to post
Share on other sites

Ah. When I get a chance tonight I will play around with that. I had it kind of stop when I messed with the first collision code and since it seems to teleport to player0 I had a suspicion it dealt with how I had the player capture it. And I'm sure having virtual sprites complicates things.

 

I'll conduct more trial and error experiments later.

Share this post


Link to post
Share on other sites

So i replaced

if !collision(player0,player1) then goto _skipcheck0

with

 if player0x <> player1x || player0y <> player1y then goto _skipcheck0

and it seemed to work... but now it doesn't seem to detect collision with the cart. So teleportation is good, collision still needs work. lol

 

I don't entirely understand other than the issues I had read about regarding the DPC+ kernel and virtual sprites but I'll take it. I'll keep reading up on this and fixing as needed. Thanks for pointing me in the right direction!

Edited by KevKelley

Share this post


Link to post
Share on other sites

SO... when I flipped the order of the collision check and added a second and third line checking the x and y coordinates it seemed to work.



 if player0x <= player1x +8 && player0x +8 >= player1x && player1y + player1height >= player0y && player1y <= player0y + player0height then goto _bagboycart

 if player0x <> player1x && player0y <> player1y then goto _skipcheck0 
 if player0x = player1x && player0y <> player1y then goto _skipcheck0
 if player0x <> player1x && player0y = player1y then goto _skipcheck0

When I didn't include that last two lines every time the x coordinates or y coordinates matched the cart would teleport to the player. So now it seems like everything is functioning as normal.

 

I'm sure there is probably a better way but at least I can move onto something else for the time...

Edited by KevKelley

Share this post


Link to post
Share on other sites

if player0x <= player1x +8 && player0x +8 >= player1x && player1y + player1height >= player0y && player1y <= player0y + player0height then goto _bagboycart

_bagboycart

 

That's a very unusual way of jumping, the _bagboycart code will be read even if that is not true and player0 is overlapping with any virtual sprite

 

then goto _bagboycart else goto _skipcheck0 would be better but why not just do something like this?

 

if !collision(player0,player1) then goto _skipcheck0
if player0x <= player1x +8 && player0x +8 >= player1x && player1y + player1height >= player0y && player1y <= player0y + player0height then player1x=player0x+3: player1y=player0y+7

Share this post


Link to post
Share on other sites

That would probably be the obvious thing to do! My brain was running around in circles. I would also have to double check but I thought I had a whole bunch of code inbetween the goto and the label and through some quick revisions I may have left some things around.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...