I’m not sure if this topic is better suited for the virtual-reality category, but I put it here just in case. Anyways I’m trying to rotate the observer around the headset’s location, but if I just rotate the observer it’ll rotate from the origin; since it isn’t translated with the headset. I’ve made an observerNode (parented to observer) which is translated to the negative of the headset’s position and I’ve made a playerNode (parented to observerNode) which is translated to the headset’s position. This seemed to work how I expected it to, the offset translates the playerNode to the location of the headset without moving everything forward infinitely. However, when I try to rotate the playerNode, it will stutter slightly then shoot both the headset and the node in a direction instantly.
playerNode = new Node();
observerNode = new Node();
observerNode.attachChild(observer);
playerNode.attachChild(observerNode);
rootNode.attachChild(playerNode);
…
oldPos = vrAppState.getFinalObserverPosition();
observerNode.setLocalTranslation(vrAppState.getFinalObserverPosition().negate());
playerNode.setLocalTranslation(oldPos);
…
if (vrAppState.getVRinput().getAxis(1, VRInputType.OculusThumbstickAxis).x != 0)
{
playerNode.rotate(0, vrAppState.getVRinput().getAxis(1,VRInputType.OculusThumbstickAxis).x * -tpf, 0);
}
Here’s an example of how the headset and node gets shot somewhere.
The problem is in code we can’t see. You need to track down where the -Infinity comes from… it’s probably what leads to the NaN.
It might also help to explain what you are actually trying to do. Like, why is observer and player different, etc… What are you actually trying to simulate?
on each line step and see when it starts show NaN or Infinite values.
Then you will know exactly what line cause issue trully.
since first 2 “ticks” work for you it seems(except X value that seems problematic), probably some later values that come from somewhere? (VR?) start giving infinity values, so you need debug when and where this infinity come from.
Its much possible it will come from VR and you will just need add some condition to skip specific values. But anyway then it would be more like VR issue.
When I check the positions of everything at the same time, it seems that the FinalObserverPosition has different values than the other two, even though I just set them a few lines before. I assume this is because the headset gets called faster for it’s own purposes. This difference causes the observer to fly out which causes the observerNode and playerNode to follow. I also see that the FinalObserverPosition is always one position ahead, so the two nodes do use older position data, but I don’t know why that is.
I’m trying to rotate the player’s viewpoint at their location. The location of the observer isn’t actually the location of the VR headset, so rotating that will rotate you from the observer’s origin which usually isn’t your location. If you just move the observer to your location it will constantly move you.
I would have to see the code in question to say anything but if nothing is changing the value and it is somehow still changing… that’s an indication that some other thread is also modifying that value.
How would I go about rotating a node around its child’s location? The headset’s location and rotation can’t be changed so it’s parented to the observer. When you move in the real world, the location of the headset changes but not the observer. If you set the observers location to that of the headset, both locations are changed and the objects self-propel themselves forever. Is there anyways to rotate both objects, but keep the location for the headset the same? Offsetting the nodes resulted in this problem, but I could have done it wrong.
The node has a transform. The transform includes both rotation and translation. To rotate around a point other than the node’s center, you’ll need to combine both rotation and translation.
The real question I have: if you don’t want these things to transform together then why have you built the hierarchy this way? Maybe you have parents/children where you don’t really want parents/children.
I’ve found out the problem, the method’s location I copied included another transform I didn’t want. I found a different method that doesn’t displace everything, but now I need to factor in rotation. Thanks for the comments.
Just remember, really the only reason to have a parent-child relationship is so that the child works within the parent’s transformation reference frame.
In a case where you go to great lengths so subvert that transform relationship then it’s a good indication that it is not a parent-child relationship. So just be sure you haven’t misunderstood why nodes have children in the first place. Hint: it’s not an organizational structure for your code… it’s 100% about transformations. That’s it.