Spatial tipping awkwardly on flat ground

I’m trying to make a stove, but every time a run my program, the stove ends up tipping awkwardly as if it was on a slop.

Screenshot of incident:

As you can see, the stove is on perfectly flat ground, but tilting anyway.
Any idea what this is?

2 Likes

The spatial may have been rotated before being exported from blender , so the actual (0,0,0) rotational state of the spatial would be the new rotation of this spatial , my opinion is to load this mesh on blender & investigate .

Nope, it looks just fine on Blender. The whole model is level with the grid.

1 Like

So ,have you added this model to physics ? & can you move this model with physics , I mean collision or gravity ?

1 Like

I’ve set up my spatial just like I set up any other spatial. The stove is colliding with the floor, but very awkwardly.

// set up my spatial
protected void setModel(String accessModel, String accessTexture) {
	System.out.println("create model");
	model = manager.loadModel("Models/"+accessModel);
	model.setLocalTranslation(pos);
	model.setLocalScale(scale);
	Material mat = new Material(manager, "Common/MatDefs/Light/Lighting.j3md");
       mat.setTexture("DiffuseMap", manager.loadTexture("Models/"+accessTexture));
	model.setMaterial(mat);
	model.addControl(phys);
	furn.attachChild(model);
}
1 Like

The Physics control(eg.RigidBodyControl/VehicleControl/CharacterControl)should be added to the physics space after this step , I donot know if your rest of the code added it or not .

EDIT :- to check if you your Spatials are added to the physics(bulletAppState.getPhysicsSpace()) or not …do :-

bulletAppState.setDebugMode(true);

In your initialization method of your SimpleApplication …

You will see physics artifacts boundaries , well you may find that this spatial has an invisible part that is stucked with the roof or the floor !

Done that. The stove is being added to the physicsSpace and the hitbox looks just fine. When a ran the player into the stove, it collided just fine.

You can just barely see the hitbox lines in this picture. Sorry, there are a lot of other things in this scene :stuck_out_tongue_winking_eye:

Edit: I forgot to mention that the stove “jumps” around before coming to rest where it is in the picture. It’s not like it’s phasing through walls or anything, it’s just another symptom of the same bug.

2 Likes

Okay , increase the mass of the stove & ensure that the stove is spawned just on the surface of the ground vector transformation values .

And set the gravity of the stove to (0,-1,0) ,

So ,

/*Create a static collisionable shape*/

RigidBodyControl stoveControl = new RigidBodyControl(CollisionShapeFactory.createMeshShape(stove),300f);
/*ground spawning of the stove*/
stove.setLocalTranslation(ground.getLocalTranslation().add(1f));
//add the control to the physics space
bulletAppState.getPhysicsSpace().add(stoveControl);
/*set the gravity that pulls the stove downward neglecting an other force*/
stoveControl.setGravity(new Vector3f(0,-1,0));
/*snap the physics location to the spatial location*/
stoveControl.getPhysics().setPhysicsLocation(stove.getLocalTranslation());

Links :

1 Like

IMO wrong "center of mass"

show me model center of mass (pivot point where phys is added / Geometry start point)

also in Blender you have “calculate center of mass velocity based” kind of.

1 Like

I agree with @oxplay2. Based on the symptoms, I would bet that the center of mass is located in one corner of the stove’s base.

If you’re using Minie, you can visualize the center of mass by setting:

bulletAppState.setDebugEnabled(true);
bulletAppState.setAxisLength(1f);

Axis lengths are specified in physics-space units. Depending on the size of the stove, you may need to adjust the setting.

1 Like

I’m a total noob at Blender, I grabbed this stove from online, and I can’t find the calculate center of mass button in v2.79 (if it exists in this version)! :angry:

In case this helps at all, here’s the model view in blender:

I’m not using Minie, sorry…

1 Like

@codex

Origin = Center of mass. (in Geometry case)

so you can even fix it manually.

but if you want auto calculated one:
https://docs.blender.org/manual/en/latest/scene_layout/object/origin.html

look for “Origin to Center of Mass”.

i even just open Blender and click like here:

aaaaaaaaaaaaaaaa

it should be same in older Blender since i did it before too.

ofc avoid “apply all transforms” after it, since it will break origin again.

Really your model should be positioned in center of 0,0,0 point, not like you have on screenshot, but its not needed, would be just more correct i think.

so you can also try “Geometry to Origin”

1 Like

Wouldn’t it be more appropriate to edit a duplicate file of the stove, set origin to the bottom center of stove, and reposition it as you stated?

Doing center of mass will make the stove sink into the floor as its a physics object.

How to do it

After saving the stove as whatever name you want:

Tab into edit mode
Select the bottom 4 corner vertices of the stove
Right mouse button select anywhere on the screen
Select Snap Vertices → Cursor to selected

Tab into Object Mode
Right mouse button select anywhere on the screen
Select Set origin → Origin to 3d cursor

And reposition the stove after:

Right mouse button select anywhere on the screen in object mode
Select Snap → Cursor to world origin
Select the stove by left mouse button drag the mouse to cover all the stove objects
Right mouse button select anywhere on the screen
Select snap selection to cursor

Apply Location, Rotation and Scale to the mesh and export.

This checklist is for 2.79 but still is applicable to 2.8+. You don’t need the armature stuff as its not animated.

https://wiki.jmonkeyengine.org/docs/3.3/tutorials/how-to/modeling/blender/blender.html#model-checklist

1 Like

bottom is still incorrect Center of mass. (well it will lay on ground visually properly, but will not be pushed/etc properly)

i would rather suggest make offset in JME, not in Blender to make it not lay inside ground.

edit:

  • or write some JME utility to calculate Center of Mass based on average surface/volume