math - Three.js Precision Terrain Collision -


've been working on game engine using webgl library three.js. have basic terrain collision working point can find face user standing on. using average or maximum y position of faces vertices not sufficient.

what formula can use find exact y position of object relative terrain face "standing" on? assuming know faces 4 vertex positions , objects vector position.

enter image description here

the plane three.planegeometry(2000,2000,128,128) augmented heightmap. image above 1 of it's faces.

i cannot put code in comment putting here. dont need math. let three.js you. can following:

var plane = new three.plane(); plane.setfromcoplanarpoints (v1, v2, v3);  // x, y, z: position of object var ray = new three.ray (new three.vector3(x, y, z), new three.vector3(0, 1, 0)); var = ray.intersectplane (plane); 

and vector3 'where' use y component change position of object.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -