[solved]Physics object always return to "standing" rotation. (what i do wrong series)


#1

Hi, i already tested physics before, but only spheres, character, static walls/etc.

but this time i want to add physics for game models like barrel in video below.

Question is: what i do wrong :smiley:

what i do is(lines merged to show simple code):

            rigidBodyControl = new RigidBodyControl(mass);
            node.addControl(rigidBodyControl);
            PhysicsSpace.getPhysicsSpace().add(rigidBodyControl);
            rigidBodyControl.setEnabled(true);

#2

It’s acting like the center of gravity is way outside of the object. Maybe your mesh is not at its own origin or something in your modeling program?


#3

hmm, to be sure, i made blender scale proper, to not scale it ingame.

then again did blender-apply for all tranforms.

then exported again to gltf, exported to j3o.

game do not scale this barrel, but anyway i still go this issue ;/

But, you said “It’s acting like the center of gravity is way outside of the object”

so i added(at the end):

rigidBodyControl.setGravity(new Vector3f(0, -1, 0));

i dont seen hello physics need to set gravity so i assume this is some issue in 3.2.2 physics (i belive it might be fixed in 3.3 or even 3.2.3). i will need to upgrade as quick as possible.

edit:

it still dont work. i thought it was fixed, but it return to its original rotation state just longer time


#4

earlier video was mass 0.1f without gravity set.

below video is mass 1f with gravity set like rigidBodyControl.setGravity(new Vector3f(0, -1, 0));

this is madness :smiley: see 30 sec +

i think i got it. when i apply in blender i had this models in position above plane (so node point is in below).

but then question for you. How do you solve it? do you have models saved in blender with center in physics center or you calculate some model bounding and move it to have geom center in node center?

what i want to say, i got ALL blender models “above” center origin that is “ground” for me.


#5

I don’t know how others do it, but I tend to make my models with their local origin in mind… so that are either sitting on the ground plane or centered on origin depending on what I will do with them.


#6

Are you using hull collision shape ?
This should not happen with cylinder shape I guess.

In case this is because mesh origin, you should be able to set origin to centre in Blender using:
Tools -> Set Origin -> Origin To Center Of Mass (Volume).

I do not know if we can set it directly on collision shape in bullet so.


#7

Tools -> Set Origin -> Origin To Center Of Mass.

wow, i probably seen this option many times, but never thought it is there :smiley:

i was thinking about using boundingBox center as center, but it might be not accurate. this option you told is very accurate i belive. The only problem is i will now need add offset when place elements in game.


#8

Try with setting your mass and gravity values to some more ‘normal’ values.

Try setting a mass of 50f on the barrel and a gravity vector of (0, -20f, 0) on the physics space. Gravity in games is often set to higher values (a value greater then 0, -9,81, 0 ) to make it feel more like in real life.


#9

thanks for info :slight_smile:

but im curious why gravity (0, -1, 0) is not the same as (0, -20, 0) ?


#10

I’ve always thought this was weird… and it’s definitely true. Real life, ~10, game life, 20. I think I finally figured out why it’s the case, though. It’s a few factors:

  1. field of view is a small part.
  2. the main part is that games overscale everything. The smallest closet is like 10x10 meters. So of course gravity will have to increase.

#11

1 meter/per/second/second is not the same as 20 meters/per/second/second?

Gravity is an acceleration.


#12

aaaaaa

is this correct, or i need to have blender center point in center of it?


#13

I believe yes.


#14

then i still do something wrong:

maybe it is because i add physics for superNode it is:

Node(some location, i add physics control to it) -> Scene Node(0,0,0) -> Cylinder Geometry([0.0, 0.53999996, 0.0]) -> mesh itself (idk how positioned it is)


#15

Hi @oxplay2,

If you go into “Edit mode” of that barrel in blender where is its center?

If it is at the bottom of the barrel that might be your problem.


#16

2 posts above, here it is:

but i think the issue is because i add it into Node instead of geometry. while node dont have center in mesh center.

i would like add physics for node, because i want put more spatials into it and follow physics.

so now i belive i should just move model center into blender origin center then it might work, right?

then just add offset when place objects in world to be “above ground”


#17

Solved! :slight_smile:

yes, since i add physics for node, not geometry (that i never did before for dynamic objects)

the geometry need to be in center of this node too, so i needed to have blender object origin match not only center of model gravity but also blender origin center, so now it works :slight_smile:

also thenks for explain about difference with gravity speed.

here result(might need add a little more mass):


#18

Great work. Needs more friction.


#19

Must stop… “That’s what…” can’t help it… “she said.”


#20

you are totally right :smiley:

it was … like you said ;p

ok now?