EvergineTeam / Feedback

Feedback, feature requests, and bug reports for Evergine.
https://evergine.com
14 stars 1 forks source link

LookAt has wrong behaviour #87

Open BChapoulie opened 3 years ago

BChapoulie commented 3 years ago

Hi,

I want to be able to change the direction of my objects. To do so I've created the following method:

public void LookInDirectionOf(Vector3 direction)
{
    var position = Transform.Position;
    var lookAt = position + direction;
    Transform.LookAt(lookAt);
}

I compute the lookAt point by adding the object position to the directional vector... however, it always has the wrong orientation. For example if I ask my object to have the direction (1,0,0) it will have the direction (-1,0,0). I've managed to make it work using var lookAt = position - direction; but this doesn't make sense.

Thanks for your help.

davilovick commented 3 years ago

Hi @BChapoulie

When you invoke the LookAt() method, the transform point its Forward direction to the desired point. And in that case your code is right.

The only thing is that you need to consider is the coordinate system of Wave Engine. In WaveEngine, an object with zero rotation and position, its forward is pointing to -Z vector. So maybe this is the source of your confusion. We use the coordinate system used by XNA, and other engines may use another references.

Best regards, David Ávila

BChapoulie commented 3 years ago

Hello,

Thanks for your reply. I understand the forward axis is -Z vector, however I have the same problem if I use an arrow model (imported from Blender in GLTF format). And I instantiate the model it has the correct -Z forward : image

Without any rotation: image

However the behaviour I described is the same, it goes in the wrong direction. If my confusion comes from here I still don't see where exactly is my problem.

EDIT: After a re-reading, I wonder, did you mean that the forward vector is -Z in the WaveEngine system? In which case the arrow in my previous screenshot is pointing backwards and I'd understand my confusion.

Best regards, Benjamin