Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Help with offscreen collision
- pw121
-
Scratcher
18 posts
Help with offscreen collision
So I’m making a scrolling platformer with enemies that move and MUST interact with walls and ground (especially the flying ones)
I can’t make a minimal (I don’t know how)
Anybody got tips?
I can’t make a minimal (I don’t know how)
Anybody got tips?
- awesome-llama
-
Scratcher
1000+ posts
Help with offscreen collision
At a conceptual level, you have to represent your objects involved in collision as primitive shapes or combinations of them.
For example you may want the ground to consist of line segments and the player a circle, capsule or rectangle.
Then you write code to perform collision detection between these primitives. A line segment/circle intersection is both simple and covers a broad range of use cases. They intersect if the sum of their radii is greater than the distance between their centers.
If your world consists of tiles on a grid, then different primitives are more applicable and it may be better to use different primitives like points and lines.
I'm answering generally as you haven't been specific with your problem.
Tip: The maths for pretty much all of these have already been derived, try searching for "[primitive A] [primitive B] intersection" on both Scratch and your web search engine of your choice.
A wikipedia article you might want to visit: https://en.wikipedia.org/wiki/Geometric_primitive
For example you may want the ground to consist of line segments and the player a circle, capsule or rectangle.
Then you write code to perform collision detection between these primitives. A line segment/circle intersection is both simple and covers a broad range of use cases. They intersect if the sum of their radii is greater than the distance between their centers.
If your world consists of tiles on a grid, then different primitives are more applicable and it may be better to use different primitives like points and lines.
I'm answering generally as you haven't been specific with your problem.
Tip: The maths for pretty much all of these have already been derived, try searching for "[primitive A] [primitive B] intersection" on both Scratch and your web search engine of your choice.
A wikipedia article you might want to visit: https://en.wikipedia.org/wiki/Geometric_primitive
Last edited by awesome-llama (May 2, 2024 02:31:22)
- Discussion Forums
- » Help with Scripts
-
» Help with offscreen collision