Hydraulic rams LookingAt node problem


#1

Hello everyone, this is my first time in a forum so I hope I’m in the right place for my problem.

I’m not a game dev, just a hobbyist, and I’m trying to make a model of an excavator work in Armory. I have all the excavator controls set up using nodes and controlled by the keyboard for now. All of the node traits are attached to the ‘boomMount’ object. My problem lies with getting the rams to work correctly. It works fine when I test it using Locked Track constraints in Blender, but I they do not transition into Armory.

I have a trait called ‘RamsTrait’ currently set up to make the left boom ram (closest to the camera) piston and ram body look at each other using the LookingAt node from the logic pack. When I hit play, everything looks to be fine - both objects are pointing at each other. But when I raise or lower the boom (up/down arrows) they do some funky things. And even more weird, to me at least, is that they move when I slew (rotate - a/d keys) the boomMount.

I have checked all my scaling are at 1 and rotations are set to zero, and the local and global orientations match. I’ve been scratching around for a few days trying to figure this out. I’m sure I’ve just made some basic, NOOB mistake but what’s left of my hair would be extremely grateful if someone could point me in the right direction with this.

Link to blend file:
https://www.dropbox.com/s/g2y7w5bnox5jvl1/excavatorTest5.blend?dl=0


Is there a more in depth tutorial on GameNodes?
Armory for simulation and visualisation
#2

I might look at this. Could you put the blend on either GitHub somewhere or upload it to the forum if it lets you. I’m sorry I can’t get to dropbox. I’ve got special network rules where I am. :smile:


#3

Thank you for this zicklag. Here’s the blend file - I missed the link button the first time.

excavatorTest5.blend (2.3 MB)


#4

Oh, I think I know what the problem is. Man, I’m having trouble with this myself. The issue is that the Set Rotation node sets the object rotation, which is actually relative to the transformation of its parent, in this case the boom. You would need to set the global rotation of the object, which is something that I have been trying to do, but I’m having a lot of weird trouble with the math. :frowning: I’ve been trying to add a “World Space” option to the Rotate Object node. Until that gets figured out I don’t know that you’ll be able to do what you’re trying to.

I like your scene, though. :slight_smile:


#5

Thank you for taking the time to look at this for me. At least now I know it’s not me going crazy or doing something totally stupid. I have been considering looking at a way doing this with a script but it’s been a while since I last did any coding and I’ll have to do a bit of study beforehand. Thanks to your answer I now have a starting point.


#6

The fastest solution would be to set the origin of the object to the world center. If all it is doing is rotating around it should work fine. If not then what you guys are already talking about will have to come along.


#7

If it can help, I think a quick way to do this in Haxe script is to see this as the rotation of a vector v1 from one initial position to another v2 = destination.

And for that, a tip, do not use Euler which under a simpler appearance actually creates imprecisions to deal with then in your code. Use quaternions.

Here is a summary (I think I have already touched a few words about it in another forum post). It is necessary to build your rotation quaternion which makes it possible to carry out the transformation from v1 to v2.

This is then done by taking the crossed product of v1, v2, in order to obtain our axis of rotation (in fact the normal to the surface represented by the 2 vectors), then to realize the scalar product of the normalized vectors, then to take the Arccos of it to get the angle, and finally plug the result into the quaternion that will serve to achieve the transformation.

There is also another way avoiding to use Arccos.:wink:

You will find all the necessary math fonctions like cross and dot of Vec4 in Armory thanks to Lubos.

Personaly, I generally prefer to use Mat4 to do everythings as it contains all the info inside only one matrix and so make transformations very compact … but need a “permis de conduire” before to use.


#8

@Didier Do you know of a good website that has learning resources for this kind of math? Something that has all of the info under one domain is preferable for me. It’s fine if you don’t; I’m just curious. :slight_smile:


#9

@zicklag
As I told in this post that for rotation, this is very easily done with quaternions in a really less expensive way than with matrix technology … I’m not sure it enchants everyone to know that quaternions are an extension of complex numbers :sunglasses: but if you already worked with/learned the Hamiltonien like in nuclear physic, you are perfectly familiarised.

Thus you have three imaginary parts and when you look at a quaternion q = a + b * i + c * j + d * k , you have i * i = -1, j * j = -1, k * k = -1
(In Armory, the qaternion is writen as x,y,z,w where q = w + x * i + y * j + z * k)

Here for example a good summary (in French langage but easy to translate) for using it properties inside Haxe/Armory https://www.irit.fr/~Veronique.Gaildrat/Ressources/EnsSupportsCours/CoursQuaternions.pdf