hello,
how can I use a 3dmax model or how to import it as a terrain? - I
in the update method in ur main game loop, u need to update the player's height according to the current height of the terrain.
do a collision detection to find the height and add that to the bouding of the player then set that as the player's y coordinate.
well, I did the collision test… but I did not find any class or method that return me the information I need.
my " Terrain " is a model that I load as a Node and the Player is another Node… - I can do what you said if I change to a TerrainPage or TerrainBlock class, but that way I cant import the model… (at least I couldnt make it work)
is there any piece of code that you could share to make things clearer to me?
theres no built in classes to do these kind stuff, u need to write ur own collision check.
heres the utility method i wrote b4, u can try to modify it to suit ur case
/**
* Find the intersection of the player's island and the ray passed in. The returned value
* is in the player's current island's local coordinate system.
* If the target cannot be found or the ray does not hit the target, return null.
* @param ray The ray defines the direction of searching.
* @param player The player that is looking for the intersection.
* @return A Vector3f which defines the intersection point.
*/
public static Vector3f findIntersection(Ray ray, Player player) {
Vector3f intersection = new Vector3f();
PickResults results = new TrianglePickResults();
// Use the ray to find all the models on the player's island which are hit by the ray.
results.clear();
player.getIsland().findPick(ray, results);
// Find the target model in the results.
boolean found = false;
boolean hit = false;
for(int i = 0; i < results.getNumber() && found == false; i++)
{
TriMesh model = (TriMesh)results.getPickData(i).getTargetMesh().getParentGeom();
if(model.getName().equalsIgnoreCase(player.getIsland().getName()))
{
found = true;
// Find the intersection where the ray hits the target's boundingBox in world
// coordinate system.
Vector3f[] vertices = new Vector3f[3];
for(int j = 0; j < model.getTriangleCount() && hit == false; j++)
{
model.getTriangle(j, vertices);
hit = ray.intersectWhere(
vertices[0].addLocal(model.getWorldTranslation()),
vertices[1].addLocal(model.getWorldTranslation()),
vertices[2].addLocal(model.getWorldTranslation()), intersection);
}
}
}
// If there is an intersection found, translate coordinate system.
if(found == true && hit == true)
{
// Translate the worldCoordinates into the player's island local coordinate system.
intersection.subtractLocal(player.getIsland().getWorldTranslation());
}
// If the target cannot be found or the ray does not hit the target, return null.
if(found == false || hit == false)
{
return null;
}
// Return the intersection.
return intersection;
}
thx again Neakor, I will try that…
Reverendo said:
thx again Neakor, I will try that..
no problem, i wrote alot collision detection methods to help my game work with models. coz basically everything in my game is a 3d max model.