Making a cube move along an infinity path in loop

im wondering if ican make a cube move at the start of the game and will keep on moving repeatedly to form an infinty sigh like path… im a real beginner and i need enlightenment

package mygame;

import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.math.Vector3f;

/** Sample 4 - how to trigger repeating actions from the main event loop.

  • In this example, you use the loop to make the player character

  • rotate continuously. */
    public class Main extends SimpleApplication {

    public static void main(String[] args){
    Main app = new Main();

    protected Geometry player;

    public void simpleInitApp() {
    /** this blue box is our player character */
    Box b = new Box(1, 1, 1);
    player = new Geometry(“blue cube”, b);
    Material mat = new Material(assetManager,
    mat.setColor(“Color”, ColorRGBA.Blue);

    /* Use the main event loop to trigger repeating actions. /
    public void simpleUpdate(float tpf) {
    // make the player rotate:
    player.setLocalTranslation(4 ,5
    tpf, 2);


1 Like

I think you are looking for cinematics and motion paths.

Or to keep it simple have a look at what setLocalTranslation does and Why your cube stays at the same Point with only its height changed to how many seconds have been passed since the last render Call

setLocalTranslation() moves the player spatial with respect to its parent in the scene graph, not with respect to its previous position. If you want motion to accumulate over time you could (in your update function) copy the current position, do vector arithmetic on it, and then invoke setLocalTranslation().

If I were trying to make a player move in a figure-eight pattern, I would probably use a lemniscate of Bernouli in parametric form. See Wikipedia for the formula.

Or you can always use the move method of spatials.

1 Like