JackFalcon Posted December 16, 2017 Share Posted December 16, 2017 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, Quote Link to comment Share on other sites More sharing options...
JackFalcon Posted December 16, 2017 Author Share Posted December 16, 2017 solution continues to be: "reverse it in blender"... Super cool to be able to pick which side the lookAt() is looking at from... Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted December 16, 2017 Share Posted December 16, 2017 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. http://playground.babylonjs.com/#CTW4AI#1 JackFalcon 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 16, 2017 Share Posted December 16, 2017 Love it! Adam reminded me of something, the other day. Stare at this for a minute or two. http://doc.babylonjs.com/classes/3.0/abstractmesh#lookat-targetpoint-yawcor-pitchcor-rollcor-space-rarr-abstractmesh-classes-3-0-abstractmesh- 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. JackFalcon 1 Quote Link to comment Share on other sites More sharing options...
Gijs Posted December 16, 2017 Share Posted December 16, 2017 (edited) You could just look at the opposite point: let diff = target.position.subtract(mesh.position); let opposite = mesh.position.add(diff.scale(-1)); mesh.lookAt(opposite); Edited December 17, 2017 by Gijs Fixed code JackFalcon 1 Quote Link to comment Share on other sites More sharing options...
JackFalcon Posted December 16, 2017 Author Share Posted December 16, 2017 You guys are the best. I'll study each... thx! Gijs 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 17, 2017 Share Posted December 17, 2017 14 hours ago, Gijs said: let diff = target.position.subtract(mesh.position);let opposite = mesh.position.add(diff.scale(-1)); 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! Gijs 1 Quote Link to comment Share on other sites More sharing options...
JackFalcon Posted December 17, 2017 Author Share Posted December 17, 2017 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/> Wingnut, Gijs and GameMonetize 3 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.