Jump to content

Vehicle Orientation Problem


photo

Recommended Posts

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

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

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

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
  • 2 weeks later...

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
×
×
  • Create New...