I want my model to run across the top of the surface and correctly alter their orientation etc to make it look like they are running on the surface.
The surface is a randomely created heightmap and my object i.e the enemy is loaded into a standard Node!
I have some movement of the object using :
Vector3f[] Points = new Vector3f[]{
new Vector3f(enemy.getLocalTranslation()),
new Vector3f(enemy.getLocalTranslation().x+1000f,enemy.getLocalTranslation().y,(enemy.getLocalTranslation().z+500f)),
};
// Create a path for the camera.
BezierCurve bc = new BezierCurve("unit path", Points);
// Create a camera node to move along that path.
// Create a curve controller to move the CameraNode along the path
CurveController cc = new CurveController(bc, enemy);
// Cycle the animation.
cc.setRepeatType(Controller.RT_CYCLE);
// Slow down the curve controller a bit
cc.setSpeed(.15f);
enemy.addController(cc);
However it doesnt take into account the shape of my randomely created height map!
hmm yeah I have seen it before but dont really like the laborious manual way its done - would it be easier to use jme physics and have that do what I want?
So the only way to do this is simply to check the position of the object on the y axis and if its below the height of the land then move it up? Seems pathetic - I used irrlicht a little while ago and by applying gravity the object stuck to the surface perfectly and then followed the contours of the land.
Those two lines simply put your model onto the surface.
But if i understand you correctly, you want to rotate your model depending on the surface.
From Flagrush tutorial9
//get the normal of the terrain at our current location. We then apply it to the up vector
//of the player.
tb.getSurfaceNormal(player.getLocalTranslation(), normal);
if(normal != null) {
player.rotateUpTo(normal);
}
Is there a better way of perhaps doing the movement - cos this is probably the problem
private void setEnemyMovement(Buster enemy){
Vector3f[] cameraPoints = new Vector3f[]{
new Vector3f(enemy.getLocalTranslation()),
new Vector3f(enemy.getLocalTranslation().x+1000f,enemy.getLocalTranslation().y,(enemy.getLocalTranslation().z+500f)),
};
// Create a path for the camera.
BezierCurve bc = new BezierCurve("camera path", cameraPoints);
// Create a camera node to move along that path.
// Create a curve controller to move the CameraNode along the path
CurveController cc = new CurveController(bc, enemy);
// Cycle the animation.
cc.setRepeatType(Controller.RT_CYCLE);
// Slow down the curve controller a bit
cc.setSpeed(.15f);
enemy.addController(cc);
}
I don't think there is enough information to comment on the movement code, we don't know what it is you're trying to do.
the models feet and body still kinda float through the surface!
For code to keep it on top of the terrain, going off the above it sounds like it does now move up and down with the terrain, but parts ofit stick through?
If so then it may be because the origin of your model is not at the bottom (probably in the middle). So anything below that is below the terrain. You could move the origin to the bottom in your modelling tool, or you could add an extra value (ie the length of the legs) to the y position.
If so then it may be because the origin of your model is not at the bottom (probably in the middle). So anything below that is below the terrain. You could move the origin to the bottom in your modelling tool, or you could add an extra value (ie the length of the legs) to the y position.
Based on what i see in the image, I guess Alric is right. Furthermore, you really have to start be nicer or at least more thankful and a whole lot more patient! You cannot expect to receive answers in a matter of hours, let alone minutes. Furthermore, you will VERY seldomly get solutions to your problems but just hints (like that good hint above from Alric).