hakan.yuceturk Posted November 20, 2014 Share Posted November 20, 2014 Hi, I want to move a vehicle to predefined coordinates.I can do it but while the vehicle is moving, its orientation is weird.I edited the codes in pathfinding examples to move the vehicle.But in my situation -as you can watch - i don't manage the vehicle's orientation successfully.Please help... Thank you in advance Adem Metin ÇALI DHMI_Demo.rar Link to comment
unclebob Posted November 25, 2014 Share Posted November 25, 2014 Hello Hakan, First things first, I recommend you to stop using absolute paths in your content and include. That's because if you want to move or share part of your project or the whole project you'll need to fix all the paths inside your code and content which is bad. In Vehicle.h file, line 78 orientation = lerp(orientation,quat(setTo(Vec3_zero,direction,vec3(1.0f,1.0f,1.0f))),ifps * 8.0f); Up vector is wrong, should be vec3(0.0f,0.0f,1.0f). Also, it's better to move NodeReference itself than node inside. Link to comment
hakan.yuceturk Posted November 25, 2014 Author Share Posted November 25, 2014 Hi Andrey, Thanks for your answer.But changing up vector is not worked. Link to comment
unclebob Posted November 28, 2014 Share Posted November 28, 2014 Hi again, Hakan! I've modified and cleaned your source code so it's working now on our latest alpha version of the engine. If you want to run it on earlier version of the engine just rename ObjectMeshStatic back to ObjectMesh. Now let's go in details of what was wrong: 1) You have to set up vector properly in setTo call. I mentioned that earlier. 2) Node.getWorldDirection() call will return normalized negative z axis of node transform which is basically not what you want. First, you have to align your node properly and then decide which vector will be forward vector for your node (I chose positive x axis). After that you have to get that vector directly from your transform via .col0/.col1/.col2 swizzles. Like in this sample: Mat4 transform = node.getWorldTransform(); Vec3 x_axis = normalize(Vec3(transform.col0)); Vec3 y_axis = normalize(Vec3(transform.col1)); Vec3 z_axis = normalize(Vec3(transform.col2)); 3) setTo call will orient object assuming its z axis is forward vector which is not what we chose earlier. That said, we need to rotate our object back so it'll be aligned properly. For x axis I do the following: quat new_orientation = quat(setTo(Vec3_zero,direction,vec3(0.0f,0.0f,1.0f))); orientation = lerp(orientation,new_orientation,ifps * 8.0f); Mat4 transform = vehicle.getWorldTransform(); vehicle_position += normalize(Vec3(transform.col0)) * ifps * 5.0f; vehicle.setWorldTransform(translate(vehicle_position) * orientation * rotateX(-90.0f) * rotateZ(90.0f)); Probably, the easiest way for you is to align your node to negative z axis in the node file and be happy. But I personally treat this as a hack as it's not industry standard for forward vector. Also, it might break consistency of your content because in that way you'll have different assets oriented differently which is probably bad especially if you're working with the team. DHMI_Demo.zip Link to comment
hakan.yuceturk Posted December 2, 2014 Author Share Posted December 2, 2014 Hi Andrey, Thanks for your answer.You used "ObjectMeshStatic"class in your code.But i don't use Unigine 2.I tried to use ObjectMesh and i does not work. Thanks again Link to comment
unclebob Posted December 2, 2014 Share Posted December 2, 2014 That's because you have to replace .mesh files as well as .node files. Just use changes I made in Vehicle.h. Link to comment
hakan.yuceturk Posted December 3, 2014 Author Share Posted December 3, 2014 Hi Andrey, thanks for your answer.This time vehicle move more smoothly but direction is not correct.You can see the situation from video.Thanks again DHMI_Demo.rar Link to comment
unclebob Posted December 11, 2014 Share Posted December 11, 2014 Hi Hakan, Sorry for the late reply. I'll have a look at this demo and report back. I guess it's a node orientation issue I told you couple posts above. Link to comment
unclebob Posted December 12, 2014 Share Posted December 12, 2014 I didn't find any .node file with your firetruck so I don't know which axis is forward. All you need to do is to align your firetruck mesh to positive x inside .node file. Link to comment
hakan.yuceturk Posted December 15, 2014 Author Share Posted December 15, 2014 Thanks Andrey.I think that my problem is about difference between vehicle orientation and pathfinding vector orintation.I will try to change vehicle orientation accordingly to the pathfinding orientation. Thanks again for your answers. Link to comment
Recommended Posts