Hello I would like to create a height system like in minecraft and I would like to know how to do it so if you know how to do it and if you can show me a ecemple or if you have documentation on it I’m interested
you mean Terrain Voxel system?
If yes:
there are many of Terrain voxel libs you can use, you just need to search and choose. there are links to someone who made own.
so you can set any height/below of terrain you need.
no I did not know this system but I want to know how to create the height you know when you press f3 on minecraft (I want to create the same system pretty much) for example it will be useful for audio systems ect …
Sorry, I am not sure what happens in minecraft when f3 is pressed. Can you please provide a screenshot of what you want?
Just display the coordinates on the y-axis
you got location of character(or anything else), so you can easly print it or project calculate it(if you need it to show other distance scale like cube)
really its basic mathematics.
lets say your character.getWorldTranslation() is 100,100,250.
you know your cube is 2f width. so your character is 50,50,100
so by default the y-axis is already “display” so imagine if I say: if (y == 0) you activate a sound is possible?
so by default the y-axis is already “display”
?
z axis is always z axis, camera direction is always camera direction. this are different things.
so imagine if I say: if (y == 0) you activate a sound is possible?
you can do anything you want, question is how you will implement this.
newbies make a lot mistakes doing raw code, without systems like ES
you should operate on EVENTS, once your character pass y == 0 there should go event, so you can add listeners and do anything you want.
Yes that’s exactly what I want
but how do you integrate the y-axis into the code?
extend your question
how to create a variable that depends on the y-axis
but y-axis is a variable itself… you dont need variable, you need to have condition to check it.
I recommend taking the tutorials and getting some experiance with jmonkey: https://wiki.jmonkeyengine.org/jme3.html#tutorials-for-beginners
The current Y axis location can be based on the camera height, or the player object height.
So we can write in the code
System.out.println(axeY);
Do it work ?
why not?
you can even do System.out.println(character.getWorldTranslation().y);
i really dont understand what you Can’t do. you should explain what you want to achieve.
And after I can add
If(y == 0)
You add a sound ?
you can, but it will work wrong.
you need to have boolean variable and just do If(y >= 0 && !isAbove) playsound(); isAbove = true.
anyway its still newbie code.
trully it should be(in any ES system):
listeners.addListener(new Listener(HeightPassedZero() {
public void onPass(){Play sound}
})
while having system that check If(y >= 0 && !isAbove) SendEvent(HeightPassedZero.class) isAbove = true
but still this is not perfect, but what i want to tell you is that you should read tutorials first.
Okay thank you that’s what I wanted
for those who want the solution, I wanted to do that.
package TestHauteurSystem;
import com.jme3.app.SimpleApplication;
import com.jme3.audio.AudioNode;
import com.jme3.audio.AudioData.DataType;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.MouseButtonTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
/**
*
* @author Hardelin
*/
public class Hauteur extends SimpleApplication {
private AudioNode audio_vague;
private Geometry player;
public static void main(String[] args) {
Hauteur app = new Hauteur();
app.start();
}
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(40);
/** just a blue box floating in space */
Box box1 = new Box(1, 1, 1);
player = new Geometry("Player", box1);
Material mat1 = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Red);
player.setMaterial(mat1);
rootNode.attachChild(player);
System.out.println(player.getWorldTranslation().y);
// player.getWorldTranslation().y += 1; for test you change the 1
if(player.getWorldTranslation().y == 0){
AudioVague();
}
System.out.println(player.getWorldTranslation().y);
}
/** We create two audio nodes. */
private void AudioVague() {
/* nature sound - keeps playing in a loop. */
audio_vague = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg", DataType.Stream);
audio_vague.setLooping(true); // activate continuous playing
audio_vague.setPositional(true);
audio_vague.setVolume(3);
rootNode.attachChild(audio_vague);
audio_vague.play(); // play continuously!
}
/** Move the listener with the a camera - for 3D audio. */
@Override
public void simpleUpdate(float tpf) {
listener.setLocation(cam.getLocation());
listener.setRotation(cam.getRotation());
}
}
ps(the cube is to be replaced of course:)