Discuss Scratch

hugobci
New Scratcher
3 posts

Collision dection between player and costume clone - help!

I'm doing this project. Infinite bike run The player switches lanes by pressing the space bar. The objective is to dodge objects going towards you. I'm not understanding how to program properly so that there is a collision between the player and the obstacle only when both are in the same lane.

I tried to create a variable that stores the layer that the clone is on and another to store the layer that the player is on and detect collision if they touch each other only if they are on the same layer. But it doesn't seem to work. Any other suggestions for my game to work?

Last edited by hugobci (July 28, 2023 15:31:02)

WindowsAdmin
Scratcher
1000+ posts

Collision dection between player and costume clone - help!

Put this code
if <touching [bicycleday_dribbble_transparent_TRIMMED v] ?> then
stop [all v]//If cone hit bike end game
end
to the clone's when I start as a clone repeat block. Right here

and if you have trouble i can remix it for you
hugobci
New Scratcher
3 posts

Collision dection between player and costume clone - help!

Thanks for the sugestion! However, if the cyclist and the clone are not on the same line, the cone should go straight through the cyclist. With the suggested code, custome always collide.

(If the cyclist is in the lower lane and the cone is in the upper lane, the cone should pass behind the cyclist.
If the cyclist is in the upper lane and the cone is in the lower lane, it should pass in front of the cyclist.)

hugobci
New Scratcher
3 posts

Collision dection between player and costume clone - help!

I arrived at a solution that served the purpose, even without any elegance:
I created two collision boxes where the bike wheels are in each of the lanes. These collision boxes stop the game (game over) when there is an obstacle and a cyclist on them at the same time.
This solution limits the dimensions of the obstacles a little, limiting the feeling of depth in each of the planes or lanes.

Powered by DjangoBB