Object rotation translated to same "visual" rotation in other object relation


Hello, i made a projectile that stops on whichever target is hit first and attaches to that target (literally- by node.attachChild). it works alright until the target is rotated.Then the arrow at the moment of attachment to the target rotates in relation to target rotation. What i want to do is to keep its rotation the same after attachment. What is the easiest (and cheapest) way to do this (i really want to avoid solutions like adding extra nodes to targets)? Is there a way to change local translation to ultimate world translation? Quaternions?

If you attach it as a child then it becomes part of that node’s “space”. It will move with that node’s space. That’s the way scene graphs work.

If you do not want it to move with that node’s space and only want the translation to change when the object moves… then move the arrow when the object moves.

You could do it with an extra node above the object to create a separate space (separate translation space and rotation spaces) but you said you don’t want to do that. So the easiest way is to just move the arrow when the object moves. You could do it with a custom control on the arrow.

If you attach it as a child then it becomes part of that node’s “space”. It will move with that node’s space. That’s the way scene graphs work I realised that, though i have no idea how to achieve the effect i want to.

If you do not want it to move with that node’s space and only want the translation to change when the object moves… then move the arrow when the object moves.
Well, i want the arrow to rotate with the new parent node, but i want to set its “old rotation” (the one it had during flight) ONCE just after attaching to new parent. Then i want it to inherit both translation and rotation.

You could do it with an extra node above the object to create a separate space (separate translation space and rotation spaces) but you said you don’t want to do that. So the easiest way is to just move the arrow when the object moves. You could do it with a custom control on the arrow.

i considered that, but there are a couple problems with such solution:

  1. it wouldnt solve my problem
  2. even if it did, then (considering i wanted this project to be a battle simulator), then the game update loop would have to keep track of all “secondary arrow nodes” , which (i am not sure, i am still learning about what has impact on performance and to what extent) seems like a pretty expensive solution taking into account that i want there to be ~300 units on screen at one time.

To better illustrate my problem i’ll attach 2 more images.

Yeah, I don’t understand the problem. I look forward to new images.

If you attach the arrow to the object then it should be fine… as long as you remembered to translate its location into local space during the process.


What i want to do, is that just after it gets attached to its target, it keeps its rotation from mid flight, and then rotates just as the target does, so new node attached to the target wouldnt do the thing.
I understand the problem, everytime the arrows rotation was changed it was by setLocalRotation(). My ideal solution would be setWorldRotation(), but there’s no such method. Is it doable by quaternions “inexpensively”?

You want to transform the arrow’s world rotation into the objects local rotation (world to local).

…while JME does not provide an automatic method for that for rotations (only translation), you can look and see what Spatial.worldToLocal() does and the do similar for rotations. Just multiply the world rotation by the same inverse that worldToLocal() makes inside.

it keeps its rotation from mid flight

I mean it keeps its rotation in relation to world, not the new target (because its how it works now)

Thank you, i’ll check it in a minute and see how it works!

Alright, that solved my problem. Solved

2 Likes