Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » 3D Collisions
- THEIMPORTANT
-
100+ posts
3D Collisions
I am making a 3d game. it uses triangles to show objects. so how do i add collisions?
Last edited by THEIMPORTANT (Nov. 24, 2024 05:14:10)
- asdf1546
-
33 posts
3D Collisions
Well, there are a few types of collisions you could add.
I'd recommend the least heavy and most common one; a sphere-triangle collision detector. It's the most effective for a 3D platformer, I used it for my character in my 3D platformer too! (https://scratch.mit.edu/projects/964921929/) I found the scripts via a Scratcher named @alltrue , so I'd recommend going to his profile and backpacking the scripts.
To implement collisions, just have it so that you have a function you can call that can check if the player is touching any triangles. In that function, cycle through all the triangles in your level, and apply the collision detection. If even one detection returns true, the player has collided with something, else, you're good to go. I'd also recommend ‘caching’ your triangles, and only sample triangles in close proximity to the player. A list that updates every few ticks that contains the indexes for said triangles will help with performance.
I'd recommend the least heavy and most common one; a sphere-triangle collision detector. It's the most effective for a 3D platformer, I used it for my character in my 3D platformer too! (https://scratch.mit.edu/projects/964921929/) I found the scripts via a Scratcher named @alltrue , so I'd recommend going to his profile and backpacking the scripts.
To implement collisions, just have it so that you have a function you can call that can check if the player is touching any triangles. In that function, cycle through all the triangles in your level, and apply the collision detection. If even one detection returns true, the player has collided with something, else, you're good to go. I'd also recommend ‘caching’ your triangles, and only sample triangles in close proximity to the player. A list that updates every few ticks that contains the indexes for said triangles will help with performance.
- Gustavotonogamer
-
23 posts
3D Collisions
hey, do you have the link for the alltrue collision project? Well, there are a few types of collisions you could add.
I'd recommend the least heavy and most common one; a sphere-triangle collision detector. It's the most effective for a 3D platformer, I used it for my character in my 3D platformer too! (https://scratch.mit.edu/projects/964921929/) I found the scripts via a Scratcher named @alltrue , so I'd recommend going to his profile and backpacking the scripts.
To implement collisions, just have it so that you have a function you can call that can check if the player is touching any triangles. In that function, cycle through all the triangles in your level, and apply the collision detection. If even one detection returns true, the player has collided with something, else, you're good to go. I'd also recommend ‘caching’ your triangles, and only sample triangles in close proximity to the player. A list that updates every few ticks that contains the indexes for said triangles will help with performance.
- Discussion Forums
- » Help with Scripts
-
» 3D Collisions