Motion from another node

I am trying to retrieve the LocalTranslation of Node B, which is a child of Node A.



I have placed Node B, to a certain distance from a Node A. So, when I rotate Node A, i get a circular motion, from Node B.



But, when I rotate or move Node A, Node B doesn’t follow its parent. It doesn’t’ move/rotate according to Node A.



So, what is going wrong here?



I haven’t attached them to rootNode or anything, hope it shouldn’t be a reason to this issue.

Yes, that is the reason, its world location is never updated, that only happens when rootNode.updateGeometricState() is called. So if you want to do this without attaching it, you have to call updateLogicalState() and updateGeometricState() on NodeA.

[java]

public static final Quaternion Q = new Quaternion().fromAngleAxis( (.1f * FastMath.PI) / 180, new Vector3f(0,1,0));

private Node A = new Node();

private Node B = new Node();

private BitmapText reportGUIText;



@Override

public void simpleInitApp() {

// guiNode.detachAllChildren();

guiFont = assetManager.loadFont(“Interface/Fonts/Default.fnt”);



reportGUIText = new BitmapText(guiFont, false);

reportGUIText.setSize(guiFont.getCharSet().getRenderedSize());

reportGUIText.setLocalTranslation(100,75,0);

guiNode.attachChild(reportGUIText);



A.attachChild(B);

}



@Override

public void simpleUpdate(float tpf) {

A.setLocalRotation(A.getLocalRotation().addLocal(Q));

A.updateGeometricState();

A.updateLogicalState(tpf);

reportGUIText.setText("Data " + B.getLocalRotation());

}[/java]



well, this doesn’t work either.



But without the updateXXX lines if i try with

[java]reportGUIText.setText("Data " + B.getWorldRotation());[/java]

This works fine, without attaching to any node(A or B) to rootNode.



So, updateXXX is running elsewhere(if it is a must for transformation), even if i dont attach those nodes to rootNode.

Well, yeah, when you read the world values the local updates now do the update in the background. But if you only read the local value its not updated, thats why you should updateGeometricState. Btw, you have to call logicalState, geometricState in that order.

I tried with updateGeometricState & updateLogicalState, just like the code above, but it is not working.

I said its in the wrong order, do the updateGeometricState() last. What exactly is not working? Also, why do you want to do this? Adding quaternions doesn’t work like you think it does, read up in the math section of the wiki. You can also just use the math functions to determine that location if thats what you want to do:

[java]

Vector3f mylocation=new Vector3f(100,75,0);

Quaternion rotation=new Quaternion();

update(float tpf){

rotation.fromAngleAxis( tpf * FastMath.PI * factor, Vector3f.UNIT_Y);

rotation.multLocal(mylocation);

spatial.setLocalTranslation(mylocation);

}

[/java]

This rotates mylocation around the y-axis in a framerate-independent manner and sets the spatials location accordingly (yes, rotation.multLocal changes the supplied vector).

Tried with reordering, but didnt work.



Ok, here is the thing i want to do.



(The green crosses the the position of concern.)





I have a turtle who is sitting at the center of the map, and who will throw you fireball from his mouth. The player will try to go through different platforming challenges while avoiding those fireballs.

The turtle and the fireball both are physics object, so, i cannt put then in the same place, cause, then the fireball will collide with the collision shape of turtle. And the fireball will be created at the tip of its mouth, so, i need a offset spawn point to start the fireball.



Now, how do i get that offset spawn point depending of the turtle and player position?



I thought about putting a node at its mouth and constraining it to the turtle, so when the turtle moves, the node also moves, and I get my desired position. But, you said Quaternion don’t work in that way.



I know, it is simple vector math, but, i can’t get things working. :frowning: tried with a lot of different combination.

you can just compute the direction between the turtle and the player (difference of their location), normalize it (so that the resulting vector length is 1 WU) then multiply this vector by an arbitrary constant let’s say…2. (you’ll have to tweak this value so that the spawn point is not in the collision shape of the turtle)

let’s call this vector offset

Then your spawn position is turtle location + offset.



It’s a quick vector math operation that you can do each time the turtle unleashes her wrath upon the poor player.

Then your spawn position is turtle location + offset.


Thanks.
This is kinda embarrassing, i forgot to do the 'add' part. :(

Any idea about the logicalState, geometricState order?
I did as @normen said, and it didn't work.

I don’t see how i could have a better idea than Normen…the guys’s a legend! :stuck_out_tongue:



Honestly I don’t know.

You can make the fireball not collide with the turtle via collision groups. Just set the collideWith group of the turtle to Group_2 and the collideWith group of the fireball to Group_2 too. Also, get off of this “abusing nodes to do math”, do it like I posted.

1 Like