How to make player collides in this scene?

I have this proyect:

index.html (3.3 KB)
With this images in the same folder as the index.html file.


bricktexture
question block
mario_small1
mario_small1_right
mario_small2
mario_small2_right

But I want when the ‘Mario’ check the collision with any bricks around the scene, it repels, like Super Mario 64. Its possible?

Check out mesh-bvh!

https://gkjohnson.github.io/three-mesh-bvh/example/bundle/characterMovement.html

How can i download this ‘mesh-bvh’ and test it?

Here’s what I’m doing for setup rn:
In your html:


        <script type="importmap">
            {
                "imports": {
                    "three": "https://threejs.org/build/three.module.js",
                    "three/examples/": "https://threejs.org/examples/",
                    "three-mesh-bvh": "https://unpkg.com/three-mesh-bvh@0.7.3/build/index.module.js"
                }
            }</script>
        <script type='module' src="./js/index.js"></script>

and then use the parts you need from this js:

for instance for generating the collision geometry I’m doing something like this:

import {MeshBVH,MeshBVHHelper,acceleratedRaycast,StaticGeometryGenerator } from 'three-mesh-bvh';

// nscene contains just the meshes I want to collide with:
const staticGenerator = new StaticGeometryGenerator( nscene );
staticGenerator.attributes = [ 'position' ];
const mergedGeometry = staticGenerator.generate();
mergedGeometry.boundsTree = new MeshBVH( mergedGeometry,{maxDepth:70});

scene.add( nscene );

I’m assuming you want a 3d solution.

Here’s the main github page for mesh-bvh which has a section on the different ways to import/use/download it:

but…
If you only need a 2d solution, you could maybe use a 2d game engine like pixijs or phaser.

1 Like

I need a 3d solution, not 2d…

Cool. Then mesh-bvh is probably a good way to go!

The files of your website appears blank for me, for example:

It’s not my website. It’s the mesh-bvh website.

You’re trying to run a locally downloaded copy from your own machine, probably by double clicking the html. That isn’t really going to work since you need to actually “host” the files somehow.

I repaired, i think:
index.html (4.0 KB)


bricktexture
question block
mario_small1
mario_small1_right
mario_small2
mario_small2_right
But at y axes it haves several bugs.