Making an object run across a surface

Hi!



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!

…disappointed by lack of community help around here! :’(

did you check the flagrush tutorial?


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?

renegadeandy said:

...would it be easier to use jme physics and have that do what I want?

Not likely.

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.

If you want something to stick to the terrain then setting it's y position to that of the terrain seems like a reasonable soluton.

If you prefer to do it by gravity, then use physics and that is a reasonable solution too.

Or you can do it a number of other ways.



Both jME and jMEPhysics have examples of mobile terrain following objects.

Well, in my update method I currently have this :



Vector3f update = enemy.getLocalTranslation();
      update.y = tb.getHeight(enemy.getLocalTranslation());
         enemy.setLocalTranslation(update);



However as the gradient of my heightmap climbs up - the model simply travels straight through it as if the terrain didnt exist!?

I would probably take two points on the surface a few feet from each other.

This way you can calculate the rotation your object should have.

So what are you suggesting - i dont get why those lines dont give me what I think should happen - what lines are you suggesting!

Can't be sure if it's your problem but you probably should use world coordinates, something like



enemy.getLocalTranslation().y = tb.getHeightFromWorld(enemy.getWorldTranslation());

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);
        }

no I have the rotating part - its the actual positioning of the object on the correct height so it looks like its on the land…



now i have



Vector3f update = enemy.getLocalTranslation();
   update.y = tb.getHeightFromWorld(enemy.getWorldTranslation());
         enemy.setLocalTranslation(update);



However the models feet and body still kinda float through the surface!

Please some body help! This is crucial!

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);
   }

oh come on! This is not a hard part of ther game - cannot believe nobody can help me put this problem to bed!

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.

What i am trying to do is very simple :



Top pic is what i want, bottom is whats happening:




Alric said:

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).

ok sorry…Just wana get stuff moving:



   Vector3f update = enemy.getWorldTranslation();
      
   update.y = terrain.getHeightFromWorld(enemy.getWorldTranslation());
   update.y += 25;
         enemy.setLocalTranslation(update);



Still doesnt work!