0

Im working with jMonkeySDK on a 3D java game. When I shoot a model/spatial with a ray it returns that spatial. So I can access things like

.getName() or .setUserData().

The Spatial as physics on it. So when the game starts it falls down from the sky. So for the beginning I want to implement a pickUp method that sets the local translation of that spatial to a certain point.

.getParent().setLocalTranslation(0, 50, 0);

(parent is "Blender Exports/woodlog/woodlog-scene_node (Node)" <- my Spatial)

(0, 50, 0) Is up in the air again. So it should fall down again. But this won't work! I can print out the translation afterwards and I get these coordinates. But the spatial does not move. So I got the parent of this parent

.getParent().getParent().setLocalTranslation(0, 50, 0);

That set the translation somehow, but the spatial moves wierd around than. First it goes to the correct point (0, 50, 0) But then it goes left, right, left, right. Then it stops and stays in the air.

Ho do I get this fixed? Why happens these wierd "animation"? And why does the mass dissappear. Well, I dont know if it disappears but the spatial should fall down again right?

Dawesign
  • 643
  • 1
  • 7
  • 25

2 Answers2

0

Once something has been put into the physics system you need to let the physics system handle moving it. You cannot just move the object in JME3 directly without (as you have seen) breaking the physics.

You need to move objects inside the physics space by applying forces to them, or remove them from the physics space. For example something that you have picked up should just be on the attachment node for your hand, with no physics at all as it will move with the person carrying it.

Tim B
  • 40,716
  • 16
  • 83
  • 128
0

The issue is that you've moved the visible part of the object (its Spatial) away from the physical part of the object (its physics Control or collision shape, the thing you added to a physicsSpace).

To teleport it directly to the fixed location you'll want to use .setPhysicsLocation(0,50f,0) or its shortcut .warp(0,50,0) for characters. Unfortunately I don't know precisely how to get to there from your spatial - working on issues in the dynamic object adding section myself.

Physics does have the advantage of doing actual pickups, by the force application system.