i find it perfect to implement a node movement based just on the XZ coordinates. But trying to make a rocket launch from a weapon i would like to care about the Y coordinate to get not just a horizontal movement.
So i Thought that the Y increase is expressed by the sine of the angle on the X axis, just like that:
the result is not the correct, first of all, i have to decrease the factY instead of increase like X and Z factors to set the Node to follow the correct direction but not the exact angle.
Maybe i have to do some better stuff, maybe have to play with matrix or quaternions???
To make a node move 'forwards' you can use matrix calculations. First off you define which axis is 'forward' for your node, depends on how the model is aligned basically so trial and error comes in here. It's most likely to be +/- on one of the 3 axes.
So let's say +Z is forward so we have our direction vector:
core::vector3df dir(0,0,1);
then we grab our node's transformation matrix:
core::matrix4 mat = node->getAbsoluteTransformation();
then we use that matrix to transform our direction vector so it now points in the same direction as the node is facing.
mat.rotateVect(dir);
Et voila, job done! You can now use that dir vector to move the node in its current direction like so:
No you don't calculate the direction yourself, it's dependent on your model you're using really...
A node doesn't have a direction it's facing at all, it has no idea of direction so you have to basically choose which direction is 'forwards' for it. So if your node is a rocket, created from a mesh then you look at the mesh and say my mesh is facing along the positive Z axis so my direction is 0,0,1. Try using 0,0,1 as your direction and see if your rocket flies in the direction which it should appear to, i.e. the node of the rocket should fly forward.
ouuo It works!!!!
thx JP,
So, mat.rotateVect(dir) aplyies the transformation to this direction vector and then you just have to add to this position the new facing coordinates as a scalar.