# SOLVED: LookAt() -> opposite direction?

## Recommended Posts

Is there a way to tell the back of a mesh.to.lookAt() something?

For example, need object to lookAt target point in opposite direction.

Any tips?

Thx,

##### Share on other sites

solution continues to be: "reverse it in blender"...

Super cool to be able  to pick which side the lookAt() is looking at from...

##### Share on other sites

Hi @aFalcon

Here ya go,

`````` // Opposite Direction ?
var lookAtOppositeDirection = true;
// All rotations or just Y ?
var negateAllRotations = true;

scene.onPointerDown = function(evt, pick){
if(!pick || !pick.hit) return;
box.lookAt(pick.pickedPoint);

if(lookAtOppositeDirection){
if(negateAllRotations){
// Opposites all rotations,  x y and z.
// e.g. if looking downwards,
// after negate it will look upwards in the opposite direction,
// (visual is same since it's a box.)
box.rotation.negate();
}
else {
// Opposites only rotation y.
// e.g. if looking downwards towards x 1,
// after, it will look downwards towards x -1.
box.rotation.y -= Math.PI;
}

}
};``````

Note; it won't work with rotationQuaternions, i don't use them, so don't know the correct values/calculations to use.

##### Share on other sites

Love it!

Adam reminded me of something, the other day.  Stare at this for a minute or two.

One might ponder what this would do:   pitchCor = yawCor = rollCor = Math.PI;  I think that would change lookAt()... into lookAwayFrom().  Right?  Maybe not.

Hope this doesn't step on any toes.  If so, Adam did it, not me.

##### Share on other sites

You could just look at the opposite point:

``````let diff = target.position.subtract(mesh.position);
mesh.lookAt(opposite);``````

Edited by Gijs
Fixed code
##### Share on other sites

You guys are the best.

I'll study each... thx!

##### Share on other sites

14 hours ago, Gijs said:

let diff = target.position.subtract(mesh.position);
mesh.lookAt(opposite);

Wow.  That's just... something.    mesh.position.add(diff.scale(-1));  Interesting!

Stuff like that... requires that special world-space math gene.  I don't have one of those.

There's stuff to be learned, there.  Cool.  The rollcor/pitchcor/yawcor = Math.PI... that version is still shorter, but i never tested if it actually works.

aWeirdo's box.rotation.negate() is a pretty interesting idea, too.   All you guys are too cool!

##### Share on other sites

Hi @aWeirdo, I see you do great work. Thanks n stuff...

Quaternions. Yay! Yeah, not too much: yaw, pitch, rollin'.... here.

Aaand it worked. Thx!

Following a motion path... and needed to look the other way!

[Kinda like my life... Jk];

hooray for negate()!!! Wait, what? negate(that); //something...

[Lolzzz. Back to work!]

Hi, @Gijs great @handle. Fun typing. Cool use of add() subract()...and scale()? Oh. Note to self: experiment ... Thx!

@Wingnut ya mon, scale(-1);  thanks for pointing that out! -->

Q: your scale is - what now? A: -1. [oh really, great.].

Brain inverts. And mind is erased. Moving on...

"world-space math gene" - heard about that!

-->The magic beans jack used to grow a beanstalk into the clouds, right?

Yeah, Math beans...? Where do we get the MathBeans!?!

magic right? Oh.... maagic! Wink.

[falcon stuffs  "rollcor/pitchcor/yawcor = Math.PI" in pocket].

Thx ... [cool stuff].

Ok, bye guys...

<jokes-not-removed/>

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.