A week ago or so i gotton marching cubes in my game and i thought it was quite boring with out collision, so i have been looking around on google. The information that i gotton was that i have to do a raycast so i have read alot of articles about it and code and what i gotton it from it is:
public static float pointOnRayTriangle(vec3 ray, vec3 origin, vec3 v0, vec3 v1, vec3 v2){
//make the vertices to smaller positions.
vec3 v11 =vec3.sub(v1, v0, null);
vec3 v22 =vec3.sub(v2, v0, null);
//creating a normal
vec3 normal =vec3.cross(v11, v22, null);
float d =Math.abs((vec3.dot(v0, normal))); //d =abs(a vertex . normal) but what vertex :?
float t =-(vec3.dot(origin, normal) +d) /vec3.dot(ray, normal);
// T =-( dot (position, triangle normal +distance) / dot ( ray, triangle normal)
return t;
}
a method that returns the time and uses the direction of the ray, the orgin of the ray, and the 3 vertices of the triangle (v0, v1, v2)
What my problem is that is when i do the raycast from the charchter feet and calculate the point of the ray i just get the player's position.
So i would like to know if i'm doing this ray alright.
Thank you in advance.