Jump to content

[SOLVED] setTo and agent direction problem


photo

Recommended Posts

Hello.

 

I want to use the setTo function to make an agent stand in mesh_position and look at agent_direction.

 

Using the following code:

 vec3 mesh_position = mesh.getWorldPosition();
 Vec3 agent_direction = route.getPoint(1) - route.getPoint(0);
 mat4 mat = setTo( mesh_position , agent_direction , vec3(0.0f,0.0f,1.0f));
 mesh.setWorldTransform(mat); //mesh is the agent

I get this:

post-624-0-44851700-1336840936_thumb.png

 

route point 0 (where the agent stands) is 0,0,1

route point 1 is -44, -54, 1

 

 

Initial position without rotation (and without applying the setWorldTransform in the code above):

post-624-0-82463500-1336840931_thumb.png

 

 

I want it to be like this:

post-624-0-91493800-1336840939_thumb.png

 

 

What do i miss?

 

Thank you for your time.

Link to comment

Hello GeorgeP,

 

The problem is that agent mesh is exported faced into -Y direction. You can check it by loading this mesh in Resource editor.

And when you load agent mesh into script you can get mesh.getDirection() and see that default direction for nodes is -Z. So you need to add extra constant rotation when applying new transformation.

 

Here is a code sample:

 

vec3 mesh_position = mesh.getPosition();
Vec3 agent_direction = route.getPoint(1) - route.getPoint(0);
mat4 mat = setTo(mesh_position,agent_direction,vec3(0.0f,0.0f,1.0f));
mesh.setWorldTransform(mat * rotateX(-90) * rotateZ(180));

Link to comment
×
×
  • Create New...