Jump to content

Photo

Collision Detection Issue - Teleporting Sprites


11 replies to this topic

#1 KevKelley ONLINE  

KevKelley

    Chopper Commander

  • 156 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Thu Feb 7, 2019 9:25 PM

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?

Attached Files



#2 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,872 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Thu Feb 7, 2019 10:17 PM

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?



#3 KevKelley ONLINE  

KevKelley

    Chopper Commander

  • Topic Starter
  • 156 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Thu Feb 7, 2019 11:19 PM

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.

#4 KevKelley ONLINE  

KevKelley

    Chopper Commander

  • Topic Starter
  • 156 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Fri Feb 8, 2019 11:48 AM

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


#5 Random Terrain OFFLINE  

Random Terrain

    Visual batari Basic User

  • 28,872 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Fri Feb 8, 2019 1:49 PM

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.



#6 KevKelley ONLINE  

KevKelley

    Chopper Commander

  • Topic Starter
  • 156 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Fri Feb 8, 2019 2:10 PM

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.

#7 KevKelley ONLINE  

KevKelley

    Chopper Commander

  • Topic Starter
  • 156 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Fri Feb 8, 2019 2:41 PM

I can probably replace it with something like if player1x <> player 6x then goto...

#8 KevKelley ONLINE  

KevKelley

    Chopper Commander

  • Topic Starter
  • 156 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Fri Feb 8, 2019 2:47 PM

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, Fri Feb 8, 2019 3:57 PM.


#9 KevKelley ONLINE  

KevKelley

    Chopper Commander

  • Topic Starter
  • 156 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Fri Feb 8, 2019 3:46 PM

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, Fri Feb 8, 2019 4:25 PM.


#10 Lillapojkenpćön OFFLINE  

Lillapojkenpćön

    Chopper Commander

  • 180 posts

Posted Mon Feb 11, 2019 7:12 PM

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



#11 KevKelley ONLINE  

KevKelley

    Chopper Commander

  • Topic Starter
  • 156 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Mon Feb 11, 2019 7:22 PM

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.

#12 KevKelley ONLINE  

KevKelley

    Chopper Commander

  • Topic Starter
  • 156 posts
  • Lots of hobbies, little time, loads of fun.
  • Location:Orlando

Posted Mon Feb 11, 2019 7:23 PM

I will definitely revisit my code and try to clean it up some more. Thanks for the tips!




0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users